Imports within try blocks are hoisted incorrectly
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, nodejs, rollup
- Ambito
- build-system
Direzione di ricerca
Inizia eseguendo i comandi di riproduzione con microbundle v0.12.0 su Node v12.17.0, quindi esamina dist/bug-test.js e confronta la posizione del require generato con lo snippet del sorgente di esm. Determina se l'hoisting ha origine in microbundle o Rollup; il lavoro è completato quando require rimane protetto dal blocco try e node dist/bug-test.js termina senza errori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
Microbundle hoists a require() call out of a try {} block in a dependency. When that require() call throws, it is not caught by the try {} block anymore.
I'm not sure whether this is an issue with microbundle or rollup. A solution to this would be not to hoist require() calls if they are in a nested block or wrap them in a function to evaluate them lazily.
How to reproduce
Make sure you have yarn installed globally, then run following commands:
mkdir bug-test
cd bug-test
yarn add microbundle esm
echo "import 'esm'" > test.js
yarn microbundle test.js --format cjs --target node --external none
node dist/bug-test.js
Expected behaviour
Commands above should execute and exit without error code.
Actual behaviour
The node dist/bug-test.js command throws this error:
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'internal/bootstrap/loaders'
Require stack:
- /Users/dany/code/bug-test/dist/bug-test.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/dany/code/bug-test/dist/bug-test.js:7:31)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/dany/code/bug-test/dist/bug-test.js' ]
The reason for this error is that there is this code in the esm module:
[…] function q(e){let t;try{const{internalBinding:n}=require("internal/bootstrap/loaders"),r=n("natives");x(r,e)&&(t=r[e])}catch(e){}return"string"==typeof t?t:""} […]
// Simplified:
try { require("internal/bootstrap/loaders") } catch (e) {}
which is modified to this by microbundle in dist/bug-test.js:
[…] var loaders = _interopDefault(require('internal/bootstrap/loaders')); […] function q(e){let t;try{const{internalBinding:n}=loaders,r=n("natives");x(r,e)&&(t=r[e]);}catch(e){}return "string"==typeof t?t:""} […]
// Simplified:
var loaders = require("internal/bootstrap/loaders")
try { loaders } catch (e) {}
Additional info
microbundle v0.12.0
Node v12.17.0
Mac OS 10.15.5
Related: https://github.com/nodejs/node/issues/33656
- Lingua principale
- JavaScript
- Stelle
- 8.1k
- Fork
- 358
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di developit/microbundle
-
CSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
developit/microbundle#1002 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
developit/microbundle#789 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
developit/microbundle#1100 · 4 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
developit/microbundle#1094 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
developit/microbundle#1093 · 3 commenti · 1 reazione ·
Tutte le issue di developit/microbundle
Issue simili
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Improve Title Support Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·