nitro: [Nitro/Unenv] cloudflare_pages build error: Could not resolve import string_decoder
Environment
node
: 18.16.1nuxt
: 3.7.4drizzle-kit
: 0.19.13@nuxtjs/tailwindcss
: 6.8.0@planetscale/database
: 1.11.0drizzle-orm
: 0.28.6pnpm
: 8.9.0
Reproduction
Clone the repo: https://github.com/andrevandal/ondevamos-web/tree/start-backend Build.
I tried to build it through pnpm and npm, but both got errors.
Describe the bug
When building the nuxt project, we got the error:
ℹ Building Nitro Server (preset: cloudflare_pages) nitro 2:18:00 PM
(node-resolve plugin) Could not resolve import "unenv/runtime/node/string_decoder/index/" in /Users/andre.vandal/projects/github.com/andrevandal/ondevamos-web/node_modules/readable-stream/lib/_stream_readable.js using exports defined in /Users/andre.vandal/projects/github.com/andrevandal/ondevamos-web/node_modules/unenv/package.json.
[nitro 2:18:03 PM] ERROR Error: Cannot resolve "unenv/runtime/node/string_decoder/index/" from "/Users/andre.vandal/projects/github.com/andrevandal/ondevamos-web/node_modules/readable-stream/lib/_stream_readable.js" and externals are not allowed!
undefined
[2:18:03 PM] ERROR Cannot resolve "unenv/runtime/node/string_decoder/index/" from "/Users/andre.vandal/projects/github.com/andrevandal/ondevamos-web/node_modules/readable-stream/lib/_stream_readable.js" and externals are not allowed!
at Object.resolveId (node_modules/nuxt/node_modules/nitropack/dist/shared/nitro.0093b44c.mjs:1879:17)
at async PluginDriver.hookFirstAndGetPlugin (node_modules/rollup/dist/es/shared/node-entry.js:25444:28)
at async resolveId (node_modules/rollup/dist/es/shared/node-entry.js:24117:26)
at async ModuleLoader.resolveId (node_modules/rollup/dist/es/shared/node-entry.js:24531:15)
at async PluginDriver.hookFirstAndGetPlugin (node_modules/rollup/dist/es/shared/node-entry.js:25444:28)
at async resolveId (node_modules/rollup/dist/es/shared/node-entry.js:24117:26)
at async ModuleLoader.resolveId (node_modules/rollup/dist/es/shared/node-entry.js:24531:15)
at async node_modules/@rollup/plugin-commonjs/dist/es/index.js:781:16
at async Promise.all (index 10)
at async node_modules/@rollup/plugin-commonjs/dist/es/index.js:773:32
Additional context
Related issues:
Logs
No response
About this issue
- Original URL
- State: open
- Created 9 months ago
- Reactions: 2
- Comments: 19 (1 by maintainers)
Any solution to this? I am currently on
firebase
preset (with no error) and want to trycloudflare
. Changing the preset tocloudflare-pages
gives this error.Hi. We are aware and this issue is under the track.
The issue is that you are using a library that is designed for Node.js and when trying to deploy to Cloudflare pages, Nitro (while trying to fix this with unenv) is not covering some subpath compatibility.
I should spend more time investigating what exact library is incompatible and a minimal (nitro only with only problematic dependency) could help to speed this up.
Was a solution ever found to @andrevandal’s problem? It seems like him and many others are experiencing the same issue with no luck.
Currently trying to build via the deployment guide for
cloudflare
and getting this exact same error. Any updates on this?Same with KnexJS
[error] [nitro] Error: Cannot resolve "pg" from "/opt/buildhome/repo/node_modules/knex/lib/dialects/redshift/index.js" and externals are not allowed!
I made this change but it didn’t work on my end, I’m still getting the same error “Cannot resolve “unenv/runtime/node/string_decoder/index/””
I got the exact same issue when importing firebase-admin inside a nitro plugin. But I figured out that it was the import that was incorrect. A minimal reproduction can be found at https://stackblitz.com/edit/github-znntty
The incorrect version was
The errors disappeared after correcting the code to the following.
I’ve got the same error with “vercel-edge” Preset:
This is my package.json file:
Building on
is fine without any problems