简体   繁体   English

错误的ERR! 缺少脚本:build:universal

[英]npm ERR! missing script: build:universal

I am trying to run my Angular application on the server side and I am facing these errors: 我试图在服务器端运行我的Angular应用程序,我正面临这些错误:

npm ERR! 错误的ERR! missing script: build:universal 缺少脚本:build:universal

npm ERR! 错误的ERR! A complete log of this run can be found in: npm ERR! 可以在以下位置找到此运行的完整日志:npm ERR!
/home/training/.npm/_logs/2018-10-03T11_50_40_593Z-debug.log /home/training/.npm/_logs/2018-10-03T11_50_40_593Z-debug.log

I used the official Angular application for doing this 我使用官方的Angular应用程序来做到这一点

https://angular.io/guide/universal https://angular.io/guide/universal

The universal build is causing errors shown below: 通用构建导致错误如下所示:

0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/nodejs', 1 verbose cli '/usr/local/bin/npm', 1 verbose cli 'run', 1 verbose cli 'build:universal' ] 2 info using npm@6.2.0 3 info using node@v10.8.0 4 verbose stack Error: missing script: build:universal 4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:155:19) 4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:63:5 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:115:5 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:418:5 4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:373:45) 4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:416:3) 4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:160:5) 4 verbose stack at /usr/local/lib/n 0如果它以ok结尾,那么它是有效的1 verbose cli ['/ usr / bin / nodejs',1 verbose cli'/ usr / local / bin / npm',1 verbose cli'run',1 verbose cli'build:universal '] 2 info使用npm@6.2.0 3 info使用node@v10.8.0 4详细堆栈错误:缺少脚本:build:universal 4 verbose stack at run(/ usr / local / lib / node_modules / npm / lib / run- script.js:155:19)4个详细堆栈位于/usr/local/lib/node_modules/npm/lib/run-script.js:63:5 4详细堆栈位于/ usr / local / lib / node_modules / npm / node_modules /read-package-json/read-json.js:115:5 4详细堆栈位于/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:418:5 4详细checkBinReferences_上的堆栈(/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:373:45)最后4个详细堆栈(/ usr / local / lib / node_modules / npm / node_modules / read-package-json / read-json.js:416:3)然后4个详细堆栈(/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:160 :5)/ usr / local / lib / n中的4个详细堆栈 ode_modules/npm/node_modules/read-package-json/read-json.js:280:12 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3) 5 verbose cwd /home/training/Desktop/vishnu/TemplateAppv6 6 verbose Linux 4.4.0-134-generic 7 verbose argv "/usr/bin/nodejs" "/usr/local/bin/npm" "run" "build:universal" 8 verbose node v10.8.0 9 verbose npm v6.2.0 10 error missing script: build:universal 11 verbose exit [ 1, true ] ode_modules / npm / node_modules / read-package-json / read-json.js:280:12 4详细堆栈位于/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78: 16 4详细堆栈在FSReqWrap.readFileAfterClose [as oncomplete](internal / fs / read_file_context.js:53:3)5 verbose cwd / home / training / Desktop / vishnu / TemplateAppv6 6 verbose Linux 4.4.0-134-generic 7 verbose argv“/ usr / bin / nodejs”“/ usr / local / bin / npm”“run”“build:universal”8详细节点v10.8.0 9详细npm v6.2.0 10错误缺少脚本:build:universal 11 verbose exit [1,真实]

As implied in my comment, you may have forgotten to add the build-script to your project: 正如我的评论中暗示的那样,您可能忘记将构建脚本添加到项目中:

From the universal docs 来自通用文档

Build and run with universal: Now that you've created the TypeScript and Webpack config files and configured the Angular CLI, you can build and run the Universal application. 使用通用构建和运行:现在您已经创建了TypeScript和Webpack配置文件并配置了Angular CLI,您可以构建并运行Universal应用程序。

First add the build and serve commands to the scripts section of the package.json: 首先将build和serve命令添加到package.json的scripts部分:

"scripts": {
    ...
    "build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
    "serve:ssr": "node dist/server",
    "build:client-and-server-bundles": "ng build --prod && ng run angular.io-example:server",
     "webpack:server": "webpack --config webpack.server.config.js --progress --colors"
    ...
}

So check you package.json and try the build again.. 所以请检查package.json并再次尝试构建..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM