olinox14
olinox14

Reputation: 6653

Nuxt 3 : Cannot find module '.output/server/node_modules/pinia-orm/dist/decorators' on nuxt start

I've got a Nuxt 3 project, with pinia and pinia-orm. SSR is on.

When I run the dev server with nuxt dev, everything runs fine.

But if I build and start the server with nuxt build and nuxt start, as soon as a page is requested, the server throws an error 500 and logs the following :

[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)

I've tried to :

Node.js is in version 18.10.0

Nuxt 3.3.3 run with Nitro 2.3.2 and 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',
    ],
    ...
})

Upvotes: 0

Views: 281

Answers (1)

olinox14
olinox14

Reputation: 6653

Solution (until the bug is fixed) is to add pinia and pinia-orm to the build.transpile array :

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

For more infos : https://github.com/nuxt/nuxt/issues/20128

Upvotes: 0

Related Questions