我有一个Nuxt 3项目,有pinia和pinia-orm。SSR打开了。
当我用nuxt dev
运行开发服务器时,一切都运行得很好。
但是如果我使用nuxt build
和nuxt 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',
],
...
})
1条答案
按热度按时间fykwrbwg1#
解决方案(直到bug被修复)是将
pinia
和pinia-orm
添加到build.transpile
数组中:更多信息:https://github.com/nuxt/nuxt/issues/20128