Open andrevandal opened 11 months ago
I've got the same error with "vercel-edge" Preset:
ℹ Building Nitro Server (preset: vercel-edge) nitro 21:32:11
(node-resolve plugin) Could not resolve import "unenv/runtime/node/string_decoder/index/" in D:\BisschenProggen\shopifyInspector\node_modules\lambdafs\node_modules\tar-stream\node_modules\readable-stream\lib\_stream_readable.js using exports defined in D:\BisschenProggen\shopifyInspector\node_modules\unenv\package.json.
[nitro 21:32:13] ERROR Error: Cannot resolve "unenv/runtime/node/string_decoder/index/" from "D:\\BisschenProggen\\shopifyInspector\\node_modules\\lambdafs\\node_modules\\tar-stream\\node_modules\\readable-stream\\lib\\_stream_readable.js" and externals are not allowed!
undefined
[21:32:13] ERROR Cannot resolve "unenv/runtime/node/string_decoder/index/" from "D:\\BisschenProggen\\shopifyInspector\\node_modules\\lambdafs\\node_modules\\tar-stream\\node_modules\\readable-stream\\lib\\_stream_readable.js" and externals are not allowed!
at Object.resolveId (/D:/BisschenProggen/shopifyInspector/node_modules/nitropack/dist/shared/nitro.0093b44c.mjs:1879:17)
at async PluginDriver.hookFirstAndGetPlugin (/D:/BisschenProggen/shopifyInspector/node_modules/rollup/dist/es/shared/node-entry.js:25444:28)
at async resolveId (/D:/BisschenProggen/shopifyInspector/node_modules/rollup/dist/es/shared/node-entry.js:24117:26)
at async ModuleLoader.resolveId (/D:/BisschenProggen/shopifyInspector/node_modules/rollup/dist/es/shared/node-entry.js:24531:15)
at async PluginDriver.hookFirstAndGetPlugin (/D:/BisschenProggen/shopifyInspector/node_modules/rollup/dist/es/shared/node-entry.js:25444:28)
at async resolveId (/D:/BisschenProggen/shopifyInspector/node_modules/rollup/dist/es/shared/node-entry.js:24117:26)
at async ModuleLoader.resolveId (/D:/BisschenProggen/shopifyInspector/node_modules/rollup/dist/es/shared/node-entry.js:24531:15)
at async /D:/BisschenProggen/shopifyInspector/node_modules/@rollup/plugin-commonjs/dist/es/index.js:781:16
at async Promise.all (index 10)
at async /D:/BisschenProggen/shopifyInspector/node_modules/@rollup/plugin-commonjs/dist/es/index.js:773:32
[21:32:13] ERROR Cannot resolve "unenv/runtime/node/string_decoder/index/" from "D:\\BisschenProggen\\shopifyInspector\\node_modules\\lambdafs\\node_modules\\tar-stream\\node_modules\\readable-stream\\lib\\_stream_readable.js" and externals are not allowed!
This is my package.json file:
{
"name": "nuxt-app",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@nuxt/devtools": "latest",
"@nuxtjs/tailwindcss": "^6.8.0",
"nuxt": "^3.7.4",
"unenv": "^1.7.4",
"vue": "^3.3.4",
"vue-router": "^4.2.5"
},
"dependencies": {
"chrome-aws-lambda": "^10.1.0",
"puppeteer": "^10.1.0",
"puppeteer-core": "^10.4.0"
}
}
Building on
Building Nitro Server (preset: node-server)
is fine without any problems
Same but a different module:
[error] [nitro] Error: Cannot resolve "bufferutil" from "/opt/buildhome/repo/node_modules/.pnpm/ws@8.11.0/node_modules/ws/lib/buffer-util.js" and externals are not allowed!
Having the same issue
[error] Cannot resolve "unenv/runtime/node/string_decoder/index/" from "/opt/buildhome/repo/node_modules/imap/node_modules/readable-stream/lib/_stream_readable.js" and externals are not allowed!
Any solution to this? I am currently on firebase
preset (with no error) and want to try cloudflare
. Changing the preset to cloudflare-pages
gives this error.
Currently trying to build via the deployment guide for cloudflare
and getting this exact same error. Any updates on this?
Same but a different module:
[error] [nitro] Error: Cannot resolve "bufferutil" from "/opt/buildhome/repo/node_modules/.pnpm/ws@8.11.0/node_modules/ws/lib/buffer-util.js" and externals are not allowed!
try yarn add bufferutil utf-8-validate
. it worked for me
Same but a different module:
[error] [nitro] Error: Cannot resolve "bufferutil" from "/opt/buildhome/repo/node_modules/.pnpm/ws@8.11.0/node_modules/ws/lib/buffer-util.js" and externals are not allowed!
try
yarn add bufferutil utf-8-validate
. it worked for me
This workaround confirmed.
But it may cause another bug on cloudflare:
Thank you.
In my nuxt.config.ts
file I have this, if it helps
rollupConfig: {
external: ["bufferutil", "utf-8-validate"],
output: {
generatedCode: {
symbols: true,
},
},
},
In my
nuxt.config.ts
file I have this, if it helpsrollupConfig: { external: ["bufferutil", "utf-8-validate"], output: { generatedCode: { symbols: true, }, }, },
Same problem, nothing changed.
the problem is that unenv
ins't converting JavaScript code to Cloudflare compatible code.
adding modules to external
(https://github.com/unjs/nitro/issues/1821#issuecomment-1884060776) just says to rollup this module will be available in runtime, which isn't (https://github.com/unjs/nitro/issues/1821#issuecomment-1884683426).
this is the map table of how unenv convert some modules: https://github.com/unjs/unenv?tab=readme-ov-file#built-in-nodejs-modules
Was a solution ever found to @andrevandal's problem? It seems like him and many others are experiencing the same issue with no luck.
Same issue here unfortunately.
Same issue here, if anyone fix this, @ me pls
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.
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
import admin from 'firebase-admin';
export default defineNitroPlugin((nitro) => {
const test = admin.initializeApp;
});
The errors disappeared after correcting the code to the following.
import { initializeApp } from 'firebase-admin/app';
export default defineNitroPlugin((nitro) => {
const test = initializeApp;
});
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
import admin from 'firebase-admin'; export default defineNitroPlugin((nitro) => { const test = admin.initializeApp; });
The errors disappeared after correcting the code to the following.
import { initializeApp } from 'firebase-admin/app'; export default defineNitroPlugin((nitro) => { const test = initializeApp; });
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/""
after some research the problem seems to be with
import {getFirestore} from "firebase-admin/firestore";
as when I remove this import, building works perfectly.
I don't know why this could be but I will keep looking.
Can add the following library also to the issue list
[nitro] Error: Cannot resolve "aws-sdk" from "/opt/atlassian/pipelines/agent/build/node_modules/@opensearch-project/opensearch/lib/aws/AwsSigv4Signer.js" and externals are not allowed!
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!
Same with String_decoder (?)
[error] Cannot resolve "unenv/runtime/node/string_decoder/index/" from "/opt/buildhome/repo/node_modules/readable-stream/lib/_stream_readable.js" and externals are not allowed!
Any chance you have set an env variable like NODE_ENV=production
?
If you did, then it is possible that the development dependencies are not being installed by Cloudflare before the build phase. For my purposes, I did want to set NODE_ENV
for my development and production builds and so I had to make sure that development dependencies were installed.
npm install --include=dev
If you are trying to run different commands for different branches, I would recommend the following:
Create separate build scripts in your package.json
. Could be something like:
"scripts": {
"build": "vite build",
"build:dev": "vite build --mode development",
}
Create a new file at your project root build.sh
- Make sure to update if CF_PAGES_BRANCH
statements with the name of your git branches. I am using branches prod
and dev
in my example.
# !/bin/bash
if [ "$CF_PAGES_BRANCH" == "prod" ]; then
package.json
on the "prod" branchecho "In Production - make sure dev dependencies are installed" npm install --include=dev echo "Building for Production" npm run build
elif [ "$CF_PAGES_BRANCH" == "dev" ]; then
package.json
on the "dev" branchecho "Building for Development" npm run build:dev
else
echo "Unrecognized Branch: $CF_PAGES_BRANCH" npm run build:dev fi
3. Lastly, in your Cloudflare dashboard for the project, make sure you specify the build command to be `bash build.sh`
This will make sure that your branch `prod` in my example is running `npm install --include=dev` before the build, and is installing all the packages.
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.
This ended up being the issue. My specific dependency was node-telegram-bot-api
. After removing it, the build was successful.
Something worth noting - this error was happening even during my local build, not specific to cloudflare.
Same with Netlify (netlify_edge) and Sharp:
[error] [nitro] Error: Cannot resolve "@img/sharp-wasm32/versions" from "/opt/build/repo/node_modules/.pnpm/sharp@0.33.4/node_modules/sharp/lib/utility.js" and externals are not allowed!
Any updates? I'am facing same problem with argon2:
[error] [nitro] Error: Cannot resolve "./argon2.win32-x64-msvc.node" from "/opt/buildhome/repo/node_modules/.pnpm/@node-rs+argon2@1.7.0/node_modules/@node-rs/argon2/index.js" and externals are not allowed!
--
No body sloved this issue ? I got exactly same error
cloudflare-pages
)19:06:13.652 | [plugin node-resolve] Could not resolve import "unenv/runtime/node/string_decoder/index/" in /opt/buildhome/repo/node_modules/readable-stream/lib/_stream_readable.js using exports defined in /opt/buildhome/repo/node_modules/unenv/package.json.
No body sloved this issue ? I got exactly same error
[info] [nitro] Building Nuxt Nitro server (preset:
cloudflare-pages
)19:06:13.652 | [plugin node-resolve] Could not resolve import "unenv/runtime/node/string_decoder/index/" in /opt/buildhome/repo/node_modules/readable-stream/lib/_stream_readable.js using exports defined in /opt/buildhome/repo/node_modules/unenv/package.json.
Using polyfills might work.
No body sloved this issue ? I got exactly same error
[info] [nitro] Building Nuxt Nitro server (preset:
cloudflare-pages
)19:06:13.652 | [plugin node-resolve] Could not resolve import "unenv/runtime/node/string_decoder/index/" in /opt/buildhome/repo/node_modules/readable-stream/lib/_stream_readable.js using exports defined in /opt/buildhome/repo/node_modules/unenv/package.json.
Using polyfills might work.
I try, It not working. No mater what we try to by pass, it not working
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.
Encountered similar issue, was not sure if I should comment here so I made a new issue with minimal repro. https://github.com/unjs/nitro/issues/2631
faced with same, is there any updates?
Same with Netlify (netlify_edge) and Sharp:
[error] [nitro] Error: Cannot resolve "@img/sharp-wasm32/versions" from "/opt/build/repo/node_modules/.pnpm/sharp@0.33.4/node_modules/sharp/lib/utility.js" and externals are not allowed!
Maybe it's because I use NuxtImg
<body> <!--StartFragment--> 14:10:46.355 | [info] .nuxt/dist/server/server.mjs 395.63 kB │ map: 880.46 kB -- | -- 14:10:46.356 | [info] ✓ built in 13.29s 14:10:46.358 | [success] Server built in 13306ms 14:10:46.472 | [success] [nitro] Generated public dist 14:10:46.512 | [info] [nitro] Building Nuxt Nitro server (preset: `cloudflare-pages`) 14:11:03.363 | [error] [nitro] Error: Cannot resolve "@img/sharp-wasm32/versions" from "/opt/buildhome/repo/node_modules/sharp/lib/utility.js" and externals are not allowed! 14:11:03.363 | 14:11:03.363 | 14:11:03.363 | undefined 14:11:03.367 | [error] Cannot resolve "@img/sharp-wasm32/versions" from "/opt/buildhome/repo/node_modules/sharp/lib/utility.js" and externals are not allowed! 14:11:03.367 | at Object.resolveId (node_modules/nitropack/dist/nitro.mjs:1970:17) 14:11:03.368 | at async PluginDriver.hookFirstAndGetPlugin (node_modules/rollup/dist/es/shared/node-entry.js:19674:28) 14:11:03.368 | at async resolveId (node_modules/rollup/dist/es/shared/node-entry.js:18355:26) 14:11:03.368 | at async ModuleLoader.resolveId (node_modules/rollup/dist/es/shared/node-entry.js:18758:15) 14:11:03.368 | at async node_modules/@rollup/plugin-commonjs/dist/es/index.js:785:16 14:11:03.368 | at async Promise.all (index 5) 14:11:03.368 | at async node_modules/@rollup/plugin-commonjs/dist/es/index.js:777:32 14:11:03.369 | at async rewriteRequireExpressionsAndGetImportBlock (node_modules/@rollup/plugin-commonjs/dist/es/index.js:1354:28) 14:11:03.369 | at async transformCommonjs (node_modules/@rollup/plugin-commonjs/dist/es/index.js:1933:23) 14:11:03.370 | at async transform (node_modules/rollup/dist/es/shared/node-entry.js:18676:16) 14:11:03.371 | 14:11:03.371 | [error] Cannot resolve "@img/sharp-wasm32/versions" from "/opt/buildhome/repo/node_modules/sharp/lib/utility.js" and externals are not allowed! 14:11:03.599 | Failed: Error while executing user command. Exited with error code: 1 14:11:03.610 | Failed: build command exited with code: 1 14:11:05.352 | Failed: error occurred while running build command
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.0Reproduction
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:
Additional context
Related issues:
Logs
No response