Server middleware is unable to access workspace (npm) module in production.
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v17.5.0
- Nuxt Version:
3.0.0-27470397.9ebea90
- Package Manager:
npm@8.4.1
- Builder:
vite
- User Config:
build
,modules
,contentful
,publicRuntimeConfig
- Runtime Modules:
nuxt-contentful-module@0.1.0
- Build Modules:
-
NOTE: nuxt-contentful-module@0.1.0 is an npm workspace module.
Reproduction
- Add server middleware file either via directory structure, (server/api/<…filename…>.js) or addServerMiddleware from @nuxt/kit.
- import a workspace module, e.g. import <workspace-module>/a/b/c.js
- Attempt to build in production.
Describe the bug
Rollup error: File /Users/…/<workspace root dir>/<nuxt app dir>/<workspace-module-dir>/a/b/c.js does not exist.
This is not an issue in development mode, only when built for production.
Additional context
I originally tried to keep this contained within the custom nuxt module, by templating out a serverMiddleware.js (since some code injection is required via addTemplate option) but arrived at the same issue as either manually adding the file in the nuxt folder structure (server/api) or adding a static template.
This may well be an upstream issue with nitro or rollup but it seems odd that a behaviour that works as expected in dev does not in production. Also open to suggestions on another way to achieve the same thing if I am using this in an unintended way, but this seems the most logical.
Standard remote npm modules seem to be resolved fine, it only seems to be an issue with workspace modules as far as I have tested.
Logs
ERROR File /Users/<user.name>/nuxt-3-contentful/nuxt-app/nuxt-contentful-module/dist/lib/createApolloClient.js does not exist.
at Job.emitDependency (/Users/<user.name>/nuxt-3-contentful/node_modules/@vercel/nft/out/node-file-trace.js:283:23)
at async Promise.all (index 17)
at async nodeFileTrace (/Users/<user.name>/nuxt-3-contentful/node_modules/@vercel/nft/out/node-file-trace.js:32:5)
at async Object.buildEnd (/Users/<user.name>/nuxt-3-contentful/node_modules/@nuxt/nitro/dist/index.mjs:292:29)
at async Promise.all (index 0)
at async /Users/<user.name>/nuxt-3-contentful/node_modules/rollup/dist/es/shared/rollup.js:23541:9
at async catchUnfinishedHookActions (/Users/<user.name>/nuxt-3-contentful/node_modules/rollup/dist/es/shared/rollup.js:22955:20)
at async rollupInternal (/Users/<user.name>/nuxt-3-contentful/node_modules/rollup/dist/es/shared/rollup.js:23527:5)
at async _build (/Users/<user.name>/nuxt-3-contentful/node_modules/@nuxt/nitro/dist/index.mjs:1102:18)
at async /Users/<user.name>/nuxt-3-contentful/node_modules/nuxt3/dist/chunks/nitro-legacy.mjs:69:7
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
No longer an issue in the current rc version… nice work @danielroe and team… Really shaping up now 😃
@danielroe sorry for the delay… https://github.com/mjrobinson86/nuxt-3-workspace-sample
Very hastily prepared but it demonstrates the issue.