编译无法在生产与NPM运行生产资产

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译无法在生产与NPM运行生产资产相关的知识,希望对你有一定的参考价值。

npm run production没有成功运行。我曾试图删除文件夹node_modules仍然运行npm install但没有。我也曾尝试卸载并从系统安装NPM,但我还是感到有同样的问题。

但是要注意运行良好,但不生产。

制作脚本的作用:

    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

我使用NPM版本6.7.0和版本的NodeJS的8.11.4脚本游戏机下面的错误在故宫错误日志:

0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'run', 'prod' ] 2 info using npm@6.7.0 3 info using node@v8.11.4 4 verbose run-script [ 'preprod', 'prod', 'postprod' ] 5 info lifecycle @~preprod: @ 6 info lifecycle @~prod: @ 7 verbose lifecycle @~prod: unsafe-perm in lifecycle true 8 verbose lifecycle @~prod: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/html/****/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 9 verbose lifecycle @~prod: CWD: /var/www/html/**** 10 silly lifecycle @~prod: Args: [ '-c', 'npm run production' ] 11 silly lifecycle @~prod: Returned: code: 1 signal: null 12 info lifecycle @~prod: Failed to exec prod script 13 verbose stack Error: @ prod: npm run production 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 emitTwo (events.js:126:13) 13 verbose stack at EventEmitter.emit (events.js:214:7) 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 emitTwo (events.js:126:13) 13 verbose stack at ChildProcess.emit (events.js:214:7) 13 verbose stack at maybeClose (internal/child_process.js:925:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) 14 verbose pkgid @ 15 verbose cwd /var/www/html/**** 16 verbose Linux 4.18.0-11-generic 17 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "run" "prod" 18 verbose node v8.11.4 19 verbose npm v6.7.0 20 error code ELIFECYCLE 21 error errno 1 22 error @ prod: npm run production 22 error Exit status 1 23 error Failed at the @ prod script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]

答案

除去包lock.json

rm package-lock.json

然后重新运行与编译:

npm run production
另一答案

我有同样的问题,因为我习惯把MIX_SENTRY_DSN_PUBLIC像这样(不工作)的WebPack:

mix.js('resources/js/app.js', process.env.MIX_SENTRY_DSN_PUBLIC/'public/js')
.sass('resources/sass/app.scss', process.env.MIX_SENTRY_DSN_PUBLIC/'public/css');

代替:

 mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');

以上是关于编译无法在生产与NPM运行生产资产的主要内容,如果未能解决你的问题,请参考以下文章

Rails 3.1 资产管道 - 为啥我的图像没有为生产进行预编译?

Rails 4 - 生产资产:预编译导致 ActiveRecord::NoDatabaseError: FATAL: database does not exist

RAILS_ENV=生产轨道资产:预编译不适用于 RSpec

运行“npm run build”需要啥?

如何刷新Rails / Sprockets以在资产之后了解生产服务器上的新清单:预编译

在生产中加载webpacker资产