question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server middleware is unable to access workspace (npm) module in production.

See original GitHub issue

Environment


  • 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:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mjrobinson86commented, Apr 26, 2022

No longer an issue in the current rc version… nice work @danielroe and team… Really shaping up now 😃

0reactions
mjrobinson86commented, Mar 31, 2022

@danielroe sorry for the delay… https://github.com/mjrobinson86/nuxt-3-workspace-sample

Very hastily prepared but it demonstrates the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located under ...
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
When you get the “cannot find module” error, or “module not found”, it means you've not installed the package you're trying to use....
Read more >
module-not-found - Next.js
The module you're trying to import is not installed in your dependencies. When importing a module from npm this module has to be...
Read more >
webpack-dev-middleware - npm
An express-style development middleware for use with webpack bundles and ... If false (but not undefined ), the server will not respond to ......
Read more >
npm-install - npm Docs
To install all modules listed in both dependencies and devDependencies when NODE_ENV environment variable is set to production , you can use --production=false ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found