【发布时间】:2019-06-29 20:40:43
【问题描述】:
我有以下 prod 脚本,我以前在另一个非常相似的项目中使用过:
#!/usr/bin/env sh
GCC=$(npm bin)/google-closure-compiler
preGccBuildSteps () {
rimraf prod dist && mkdir prod && ln -sfn ../../css prod/css && \
spago build && spago bundle-module --main Metajelo.UI --to prod/index.prod.js && \
cp static/index.* prod/
}
preGccBuildSteps || { echo 'preGccBuildSteps failed' ; exit 1; }
"$GCC" --js prod/index.prod.js --js_output_file prod/index.opt.js && \
echo $(pwd) && \
parcel build --public-url ./ prod/index.html
echo $(pwd) 是最近添加的,以尝试确认我的神智正常,但不幸的是,当我使用 npm run prod 运行它时,它会打印出预期的目录,并且我收到一个似乎不是很有帮助的错误:
/wd/app
[Error: ENOENT: no such file or directory, scandir 'build'] {
errno: -2,
code: 'ENOENT',
syscall: 'scandir',
path: 'build'
}
/wd/node_modules/parcel-luxe/lib/parser.js:44
files.forEach(function (file) {
^
TypeError: Cannot read property 'forEach' of undefined
at /wd/node_modules/parcel-luxe/lib/parser.js:44:11
at /wd/node_modules/parcel-luxe/lib/reader.js:9:14
at FSReqCallback.oncomplete (fs.js:136:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! purescript-metajelo-ui@ prod: `../scripts/prod`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the purescript-metajelo-ui@ prod 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/brandon/.npm/_logs/2019-06-29T20_34_37_583Z-debug.log
注意/wd/app 是pwd 的预期输出。
好的,很明显问题出在最后一个命令parcel build --public-url ./ prod/index.html。
但是当我直接在终端中运行它时,即使在npm run prod 出现错误之后,我实际上还是成功了:
brandon@4747aec8d9e1:/wd/app$ parcel build --public-url ./ prod/index.html
✨ Built in 6.10s.
dist/prod.0a64bfcf.js.map 547.15 KB 107ms
dist/prod.0a64bfcf.js 253.9 KB 5.56s
dist/index.html 5.01 KB 375ms
dist/prod.74dcbc56.css.map 4.46 KB 5ms
dist/icomoon.0cf994d0.svg 3.53 KB 40ms
dist/icomoon.6cd840b1.eot 1.95 KB 40ms
dist/icomoon.a7482a13.woff 1.86 KB 39ms
dist/prod.74dcbc56.css 1.82 KB 5.50s
dist/icomoon.712d3017.ttf 1.79 KB 39ms
那么为什么从npm run prod 运行时会失败?
【问题讨论】:
-
如果我将此命令添加为独立脚本:` "parcel": "parcel build --public-url ./prod/index.html",
, and donpm run parcel, it fails with the same error message. Only thing I can think is thatnpm ` 以某种方式扰乱了环境。