gpt4 book ai didi

node.js - nuxt start 需要 node_modules 才能运行

转载 作者:搜寻专家 更新时间:2023-10-31 23:19:39 25 4
gpt4 key购买 nike

我有一个添加最少的 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"
}
}

本地开发看起来不错,本地 buildstart 似乎工作正常。然而,当我构建 Docker 镜像时,一切都变得糟糕了。请注意这不是 Docker 的问题,如果我在自己的机器上的新目录中运行相同的步骤也是如此。

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 插入 .nuxtstatic 目录后,这一切都消失了。似乎有些模块没有捆绑。我的 nuxt.config.js 文件是这样的

module.exports = {
head: {
// Skipping noise...
},
modules: [
[ 'nuxt-fontawesome', {
component: 'fa',
imports: [
{ set: '@fortawesome/fontawesome-free-brands' },
]
}],
],
loading: { color: '#3B8070' },
build: {
extend (config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})

// *** NOTE: In practice, I'm only using FA brands here, not the others ***

config.resolve.alias['@fortawesome/fontawesome-free-brands$'] = '@fortawesome/fontawesome-free-brands/shakable.es.js'
}
}
}
}

我做错了什么吗?

最佳答案

我发现 Nuxt 构建不会在 node_modules 中打包文件,所以如果你想将所有依赖打包到 .nuxt 中,你应该使用 nuxt build --standalone

请看这里:https://github.com/nuxt/nuxt.js/issues/4292

希望这对你有帮助:)

关于node.js - nuxt start 需要 node_modules 才能运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50700680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com