-
-
Notifications
You must be signed in to change notification settings - Fork 34
[CF] External dependencies outside root folder not found (monorepo) #123
Description
Hey 👋🏻
I'm here again, reporting a similar bug like nuxt/nuxt#11465, again due to a monorepo structure but this time limited to the CloudFlare preset.
Reproduction
- Clone the repo https://github.com/manniL/nitro-monorepo-vue-not-found
- Install deps (
yarn) - (optional) Run
cd packages/app && yarn dev-> this works fine ✅ - Run
NITRO_PRESET=cloudflare yarn generate(still in the app subfolder) to generate your worker - See the following error
The first trace points directly to const Vue = __webpack_require__(/*! vue */ "vue");
Stack trace
FATAL [worker] Cannot read property 'use' of undefined 17:47:42
at Module. (node_modules/.cache/nuxt/dist/server/server.js:3852:24)
at webpack_require (node_modules/.cache/nuxt/dist/server/server.js:27:30)
at Object. (node_modules/.cache/nuxt/dist/server/server.js:1629:18)
at webpack_require (node_modules/.cache/nuxt/dist/server/server.js:27:30)
at node_modules/.cache/nuxt/dist/server/server.js:118:18
at node_modules/.cache/nuxt/dist/server/server.js:121:1
at createCommonjsModule (node_modules/.cache/nuxt/nitro/index.js:656:9)
at Object. (node_modules/.cache/nuxt/nitro/index.js:14363:14)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
╭─────────────────────────────────────────────────────────────────╮
│ │
│ ✖ Nuxt Fatal Error │
│ │
│ TypeError: [worker] Cannot read property 'use' of undefined │
│ │
╰─────────────────────────────────────────────────────────────────╯
error Command failed with exit code 1.
In this case, Vue.use is called somewhere throughout the application but couldn't be found.
Workaround
A very naive workaround is to change the moduleDirectories to include upath.resolve(nitroContext._nuxt.rootDir, "../../node_modules"). Then, the above error does not occur anymore.
Of course, this isn't optimal but I'm not sure what the best strategy would be here for "full monoerepo support". Maybe making the moduleDirectories configurable? 🤔
nohoisting some packages like vue would work as well but has major disadvantages (e.g. lots of package dupes, errors on circular deps etc).
