Использование GULP js с NPM и сообщением об ошибке React ERROR - PullRequest
0 голосов
/ 01 ноября 2019

если кто-нибудь знает, как исправить эту ошибку, я хотел бы услышать ваше мнение. Большое спасибо, я боролся с этой проблемой весь день ... следует отметить, что папка / проект клиента находится внутри папки / проекта на сервере, и они оба используют response

Мой gulpfile. js

const gulp = require("gulp");
const tsProject = require("gulp-typescript").createProject("tsconfig.json");
const gulpSourcemap = require("gulp-sourcemaps");
const path = require("path");
const browserSync = require("browser-sync").create();
const spawn = require("child_process").spawn;
const dotenv = require("dotenv").config();

/**
 * watch client and server build directories for new compiled output, reload browser
 */
gulp.task("watch", () => {
    gulp.watch(["server/**/*.ts"], gulp.series("compile:server", "browser:reload"));
    gulp.watch(["client/src/**/*"], gulp.series("compile:client", "browser:reload"));
});

gulp.task("build:server", (done) => {
    startWorker("npm", ["run", "build"], { }, done);
});
gulp.task("compile:server", () => {
    return gulp.src("server/**/*.ts")
        .pipe(gulpSourcemap.init())
        .pipe(tsProject())
        .pipe(gulpSourcemap.write(".", { sourceRoot: "./", includeContent: false }))
        .pipe(gulp.dest("build/server"));
});

/**
 * build the React client
 */
gulp.task("build:client", (done) => {
    startWorker("npm", ["run", "build"], {
        cwd: path.join(__dirname, "./client/")
    }, done);
});
gulp.task("compile:client", (done) => {
    startWorker("npm", ["run", "compile"], {
        cwd: path.join(__dirname, "./client/")
    }, done);
});

/**
 * auto reload browser
 */
gulp.task("browser:reload", (done) => {
    browserSync.reload();
    done();
});

/**
 * initialize browser-sync to auto-reload browser
 */
gulp.task("browser:init", (done) => {
    browserSync.init({
        proxy: `http://localhost:${process.env.LISTEN_PORT}`,
        // open: false,
        // watch: ["build", "client/build"]
    });
    done();
});

gulp.task("run:server", (done) => {
    startWorker("nodemon", [
        "--inspect", "build/server/index.js", "--watch", "build", "--ignore", "node_modules"
    ], {}, done);
});

gulp.task("build", gulp.parallel("build:client", "build:server"));

gulp.task("dev-helpers", gulp.parallel("run:server", "browser:init", "watch"));

gulp.task("default", gulp.series("build", "dev-helpers"));

/*******************************************************************************
 *                               Utilities                                     *
 *******************************************************************************/
/** spawn a worker process and pipe stdout */
const startWorker = (cmd, args, config, doneCallback) => {
    const worker = spawn(cmd, args, {
        stdio: "inherit",
        ...config
    });
    worker.on("data", (data) => {
        console.log(data.toString())
    });
    worker.on("error", (data) => {
        console.log(data.toString())
    });
    worker.on("exit", () => {
        doneCallback()
    });
}

Сообщение об ошибке

mv: rename build/* to ../build/client/*: No such file or directory
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 compile: `react-scripts build; rm -rf ../build/client; mkdir ../build/client; mv build/* ../build/client/ && rm -rf build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the client@0.1.0 compile script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/syranol/.npm/_logs/2019-11-01T07_36_09_021Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 build: `npm install; npm run compile`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the client@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/syranol/.npm/_logs/2019-11-01T07_36_09_080Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! studyseat@1.0.0 build-client: `cd client && npm run build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the studyseat@1.0.0 build-client script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/syranol/.npm/_logs/2019-11-01T07_36_09_138Z-debug.log

Мой полный журнал запуска

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'compile' ]
2 info using npm@6.4.1
3 info using node@v10.13.0
4 verbose run-script [ 'precompile', 'compile', 'postcompile' ]
5 info lifecycle client@0.1.0~precompile: client@0.1.0
6 info lifecycle client@0.1.0~compile: client@0.1.0
7 verbose lifecycle client@0.1.0~compile: unsafe-perm in lifecycle true
8 verbose lifecycle client@0.1.0~compile: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/syranol/Desktop/capstone/StudySeat/client/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/syranol/Desktop/capstone/StudySeat/client/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/syranol/Desktop/capstone/StudySeat/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/syranol/Desktop/capstone/StudySeat/node_modules/.bin:/Users/syranol/Documents/Documents/bin:/Users/syranol/Documents/Documents/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle client@0.1.0~compile: CWD: /Users/syranol/Desktop/capstone/StudySeat/client
10 silly lifecycle client@0.1.0~compile: Args: [ '-c',
10 silly lifecycle   'react-scripts build; rm -rf ../build/client; mkdir ../build/client; mv build/* ../build/client/ && rm -rf build' ]
11 silly lifecycle client@0.1.0~compile: Returned: code: 1  signal: null
12 info lifecycle client@0.1.0~compile: Failed to exec compile script
13 verbose stack Error: client@0.1.0 compile: `react-scripts build; rm -rf ../build/client; mkdir ../build/client; mv build/* ../build/client/ && rm -rf build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid client@0.1.0
15 verbose cwd /Users/syranol/Desktop/capstone/StudySeat/client
16 verbose Darwin 18.0.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "compile"
18 verbose node v10.13.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error client@0.1.0 compile: `react-scripts build; rm -rf ../build/client; mkdir ../build/client; mv build/* ../build/client/ && rm -rf build`
22 error Exit status 1
23 error Failed at the client@0.1.0 compile script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
...