Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nitro build for edge presets should use browser target #410

Closed
warflash opened this issue Aug 10, 2022 · 7 comments
Closed

nitro build for edge presets should use browser target #410

warflash opened this issue Aug 10, 2022 · 7 comments
Labels
bug Something isn't working workaround available

Comments

@warflash
Copy link

warflash commented Aug 10, 2022

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 warflash changed the title require(module) wrapped in try catch seems to break nitro builds for edge targets module.require() wrapped in try catch seems to break nitro builds for edge targets Aug 10, 2022
@warflash
Copy link
Author

warflash commented Aug 19, 2022

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 warflash changed the title module.require() wrapped in try catch seems to break nitro builds for edge targets Failing nitro builds for edge targets Aug 23, 2022
@fantasyflip
Copy link

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

@warflash
Copy link
Author

warflash commented Aug 23, 2022

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
Copy link
Author

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 🤔

@victorkwok97
Copy link

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.

@Hebilicious Hebilicious added the bug Something isn't working label Jun 30, 2023 — with Volta.net
@Hebilicious Hebilicious changed the title Failing nitro builds for edge targets nitro build for edge presets should use browser target Jun 30, 2023
Copy link
Member

Hebilicious commented Jun 30, 2023

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

@Hebilicious
Copy link
Member

This is on our radar, let's track with #1371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working workaround available
Projects
None yet
Development

No branches or pull requests

4 participants