nuxt start需要存在node_modules才能运行

时间:2018-06-05 12:57:39

标签: node.js docker webpack node-modules nuxt.js

我有一个select id_produkt, case when bp_stan_produkt.id_stan_produkt = 313 then 'TAK' else 'NIE' end as "313" from bp_stan_produkt where data_do is not null union select id_produkt, case when bp_stan_produkt.id_stan_produkt = 314 then 'TAK' else 'NIE' end as "314" from bp_stan_produkt where data_do is not null 项目,添加量很少。我的nuxt-community/starter-template看起来像这样

package.json

本地开发看起来很好,本地{ // ... "scripts": { "dev": "nuxt", "build": "nuxt build", "docker-image": "nuxt build && docker build -t unijobs-www-temp .", "start": "nuxt start", "generate": "NODE_ENV=production nuxt generate", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "precommit": "npm run lint" }, "dependencies": { "@fortawesome/fontawesome": "^1.1.8", "@fortawesome/fontawesome-free-brands": "^5.0.13", "@fortawesome/fontawesome-free-regular": "^5.0.13", "@fortawesome/fontawesome-free-solid": "^5.0.13", "@fortawesome/vue-fontawesome": "0.0.22", "nuxt": "^1.0.0", "nuxt-fontawesome": "^0.2.0", "node-sass": "^4.9.0", "sass-loader": "^7.0.2" }, "devDependencies": { "babel-eslint": "^8.2.1", "eslint": "^4.15.0", "eslint-friendly-formatter": "^3.0.0", "eslint-loader": "^1.7.1", "eslint-plugin-vue": "^4.0.0" } } build似乎工作正常。但是,当我构建Docker镜像时,它都向南。 请注意这不是Docker的问题,如果我在自己的机器上,在新目录中运行相同的步骤,情况也是如此。

start

这是我在日志中找到的内容:

FROM node:stretch

ENV NODE_ENV=production
ENV HOST=0.0.0.0
EXPOSE 3000

RUN npm -g i nuxt
RUN mkdir -p /app
ADD .nuxt /app/.nuxt
ADD static /app/static
WORKDIR /app

CMD ["nuxt", "start"]

但是,只要我在2018-06-05T12:27:19.910Z nuxt:render Rendering url / { Error: Cannot find module 'core-js/library/fn/promise' from '/app' at Function.module.exports [as sync] (/usr/local/lib/node_modules/nuxt/node_modules/resolve/lib/sync.js:42:15) at r (/usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8332:44) at Object.<anonymous> (server-bundle.js:1429:18) at __webpack_require__ (server-bundle.js:27:30) at Object.module.exports.module.exports (server-bundle.js:105:31) at __webpack_require__ (server-bundle.js:27:30) at Object.<anonymous> (server-bundle.js:1218:138) at __webpack_require__ (server-bundle.js:27:30) at server-bundle.js:92:18 at Object.<anonymous> (server-bundle.js:95:10) at evaluateModule (/usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8338:21) at /usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8396:18 at new Promise (<anonymous>) at /usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8388:14 at Object.renderToString (/usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8564:9) at Renderer.renderRoute (/usr/local/lib/node_modules/nuxt/lib/core/renderer.js:344:41) code: 'MODULE_NOT_FOUND', statusCode: 500, name: 'NuxtServerError' } node_modules目录旁边插入.nuxt,它就会消失。似乎有些模块没有捆绑在一起。我的static文件就像

nuxt.config.js

我做错了吗?

1 个答案:

答案 0 :(得分:2)

我发现Nuxt构建不会在node_modules中捆绑文件,因此,如果要将所有依赖项捆绑到.nuxt,则应使用 nuxt build --standalone

请参见此处:https://github.com/nuxt/nuxt.js/issues/4292

希望这会对您有所帮助:)