构建VueJS项目报错如何解决?

How to solve the error while building a VueJS project?

我在前端使用 VueJS,在后端使用 Django。对于生产,我将所有 VueJS 编译包移动到 django 中的 Static/dist。而我把VueJS中index.html的内容屏蔽为django中的base.html。并更改了 url.py,这样当调用 localhost:8000 时,它会给出 base.html,这会给出 VueJS 的 index.html。

当我尝试使用 npm run buid 进行构建时,它抛出了如图所示的错误


ERROR  Build failed with errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! e_cell_frontend@0.1.0 build: `vue-cli-service build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the e_cell_frontend@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!     /home/vagrant/.npm/_logs/2021-08-05T04_54_44_578Z-debug.log

日志文件如图:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using npm@6.14.4
3 info using node@v10.19.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle e_cell_frontend@0.1.0~prebuild: e_cell_frontend@0.1.0
6 info lifecycle e_cell_frontend@0.1.0~build: e_cell_frontend@0.1.0
7 verbose lifecycle e_cell_frontend@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle e_cell_frontend@0.1.0~build: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/vagrant/VueJS/e_cell_frontend/node_modules/.bin:/home/vagrant/.vscode-server/bin/c3f126316369cd610563c75b1b1725e0679adfb3/bin:/home/vagrant/.local/bin:/home/vagrant/.vscode-server/bin/c3f126316369cd610563c75b1b1725e0679adfb3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle e_cell_frontend@0.1.0~build: CWD: /home/vagrant/VueJS/e_cell_frontend
10 silly lifecycle e_cell_frontend@0.1.0~build: Args: [ '-c', 'vue-cli-service build' ]
11 silly lifecycle e_cell_frontend@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle e_cell_frontend@0.1.0~build: Failed to exec build script
13 verbose stack Error: e_cell_frontend@0.1.0 build: `vue-cli-service build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid e_cell_frontend@0.1.0
15 verbose cwd /home/vagrant/VueJS/e_cell_frontend
16 verbose Linux 5.4.0-73-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
18 verbose node v10.19.0
19 verbose npm  v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error e_cell_frontend@0.1.0 build: `vue-cli-service build`
22 error Exit status 1
23 error Failed at the e_cell_frontend@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

我尝试清除缓存,删除node_modules并重新安装它们,但没有用。谁能帮我解决这个问题。

我解决了这个问题。问题是您需要记住,您需要先 运行 npm run serve 检查代码中是否有任何错误,然后再构建它。我打错了,忘了执行 npm run serve,所以我不知道原来的错误。所以 运行 npm run server 如果一切都好的话。构建它。