Nuxt 3:无法在nuxt start上找到模块“.output/server/node_modules/pinia-orm/dist/decorators”

xoefb8l8  于 2023-04-11  发布在  Node.js
关注(0)|答案(1)|浏览(543)

我有一个Nuxt 3项目,有piniapinia-orm。SSR打开了。
当我用nuxt dev运行开发服务器时,一切都运行得很好。
但是如果我使用nuxt buildnuxt start构建并启动服务器,只要请求一个页面,服务器就会抛出错误500并记录以下内容:

[nuxt] [request error] [unhandled] [500] Cannot find module '/home/workspace/.output/server/node_modules/pinia-orm/dist/decorators' imported from /home/workspace/.output/server/chunks/app/server.mjs
  at new NodeError (node:internal/errors:393:5)  
  at finalizeResolution (node:internal/modules/esm/resolve:323:11)  
  at moduleResolve (node:internal/modules/esm/resolve:916:10)  
  at defaultResolve (node:internal/modules/esm/resolve:1124:11)  
  at nextResolve (node:internal/modules/esm/loader:163:28)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)  
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)  
  at link (node:internal/modules/esm/module_job:75:36)

我试过:

  • 删除所有缓存和nuxt生成的文件从头开始重建
  • 移动package.json中devDependencies中的@pinia/nuxt和@pinia-orm/nuxt依赖项,如这里所建议的,即使文档另有指示
  • 同时安装pinia和@pinia/nuxt,或者按照这里的建议只安装@pinia/nuxt
  • 使用npm并强制安装pinia,就像这里建议的那样(我在这个项目中使用yarn)
  • 删除nuxt.config.ts中的autoImports部分,如某个地方所建议的

Node.js版本为18.10.0
Nuxt 3.3.3运行Nitro 2.3.2和vite v4.2.1

package.json

"dependencies": {
    ...
    "@pinia-orm/nuxt": "^1.1.7",
    "@pinia/nuxt": "0.4.7",
    ...
    "nuxt": "^3.3.2",
    "pinia-orm": "^1.5.1",
},
"devDependencies": {
    ...
}

nuxt.config.ts

export default defineNuxtConfig({
    ssr: true,
    ...
    modules: [
        ...
        [
            '@pinia/nuxt',
            {
                autoImports: [
                    // automatically imports `usePinia()`
                    'defineStore',
                    // automatically imports `usePinia()` as `usePiniaStore()`
                    ['defineStore', 'definePiniaStore'],
                ],
            }
        ],
        '@pinia-orm/nuxt',
    ],
    ...
})
fykwrbwg

fykwrbwg1#

解决方案(直到bug被修复)是将piniapinia-orm添加到build.transpile数组中:

export default defineNuxtConfig({
    // ...
+   build: {
+     transpile: ['pinia', 'pinia-orm']
+   },
    // ...
  })

更多信息:https://github.com/nuxt/nuxt/issues/20128

相关问题