nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Failing nitro builds for edge targets

Open warflash opened this issue 1 year ago • 5 comments

Environment

nitro 0.4.18

Reproduction

Bridge: https://stackblitz.com/edit/github-mdiu2d?file=pages%2Findex.vue Nuxt 3: https://stackblitz.com/edit/github-ouxssx?file=nuxt.config.ts

npm run build

Describe the bug

Building the nitro server fails for edge deploy targets such as cloudflare in this particular reproduction. Error: Rollup error: Cannot resolve "asciify-image" from "/home/projects/github-mdiu2d/node_modules/@probe.gl/log/dist/es5/node/node-asciify-image.js" and externals are not allowed!

Choosing a deploy target other then edge makes the issue disappear

Additional context

The probe.gl library used here wraps module.require() inside of a try catch block which I suspect might be causing the issue in nitro. https://github.com/uber-web/probe.gl/blob/master/modules/log/src/node/node-asciify-image.ts

Logs

No response

warflash avatar Aug 10 '22 21:08 warflash

Another guess on the issue would be that nitro does not properly respect the browser field in the modules package.json

"browser": {
    "asciify-image": false,
    "./src/node/node-asciify-image.ts": false,
    "./dist/node/node-asciify-image.js": false,
    "./dist/es5/node/node-asciify-image.js": false,
    "./dist/esm/node/node-asciify-image.js": false
  }, 

For node based presets the browser field is not really relevant but web workers should probably respect it? The browser excluded files also correlate with the error message hence the guess.

Anyways, if theres anything else I can do, please let me know as getting this running is the last thing atm that's blocking us from migrating to nuxt 3❤

warflash avatar Aug 19 '22 22:08 warflash

Running into the same issue with deck.gl and cloudflare workers at the moment, did you happen to find any workaround @warflash?

fantasyflip avatar Aug 23 '22 13:08 fantasyflip

Running into the same issue with deck.gl and cloudflare workers at the moment, did you happen to find any workaround @warflash?

I did not no. Just gotta wait and hope it's something that can be resolved soon I guess🤞

warflash avatar Aug 23 '22 14:08 warflash

Small update, due to changes in either a nuxt or nitro release there is now warnings being logged before the build:

WARN 'requireFromFile' is not exported by '__vite-browser-external' WARN 'requireFromFile' is not exported by '__vite-browser-external' WARN 'requireFromString' is not exported by '__vite-browser-external' WARN 'requireFromString' is not exported by '__vite-browser-external' WARN 'toBuffer' is not exported by '__vite-browser-external' WARN 'toBuffer' is not exported by '__vite-browser-external' WARN 'readdir' is not exported by '__vite-browser-external' WARN 'stat' is not exported by '__vite-browser-external' WARN 'open' is not exported by '__vite-browser-external' WARN 'close' is not exported by '__vite-browser-external' WARN 'fstat' is not exported by '__vite-browser-external' WARN 'read' is not exported by '__vite-browser-external' WARN '_readToArrayBuffer' is not exported by '__vite-browser-external' WARN 'readFileSync' is not exported by '__vite-browser-external' WARN 'writeFile' is not exported by '__vite-browser-external'
WARN 'writeFileSync' is not exported by '__vite-browser-external' WARN 'nodeAsciifyImage' is not exported by '__vite-browser-external'

Still only edge deploys are failing, node.js targets build fine 🤔

warflash avatar Aug 31 '22 22:08 warflash

https://stackblitz.com/edit/github-dfijad-x7236k?file=nuxt.config.ts,app.vue,package.json

Same issue with mongodb and aws-sdk packages as well which have require inside of a try catch block.

victorkwok97 avatar Sep 01 '22 12:09 victorkwok97

A workaround for this issue is to use the alias option in nuxt.config.ts

Hebilicious avatar Jun 30 '23 23:06 Hebilicious

This is on our radar, let's track with https://github.com/unjs/nitro/issues/1371

Hebilicious avatar Jul 02 '23 02:07 Hebilicious