parcel: Parcel reports "Export 'X' is not defined" if a ESM module tries to export a `function`
π bug report
If in an ESM module the export statement refers to a function, this consistently fails the build.
π Configuration (.babelrc, package.json, cli command)
To reproduce, clone: https://github.com/mweststrate/parcel-bug, yarn install, yarn build
This happens with an out-of-the-box configuration with parcel, no .babelrc, package.json:
{
"name": "parcel-bug",
"version": "1.0.0",
"main": "index.js",
"author": "Michel Weststrate <mweststrate@gmail.com>",
"license": "MIT",
"devDependencies": {
"parcel-bundler": "^1.12.2"
},
"scripts": {
"build": "parcel public/index.html"
},
"dependencies": {
"immer": "^2.1.4"
}
}
π€ Expected Behavior
The project should build without error, even when an export statement references a function
π― Current Behavior
Build failure, any referred function is reported as Export '...' is not defined
When using the immer package with parcel I consistently get the following build error:
π¨ /home/michel/Dropbox/presentaties/parcel-bug/node_modules/immer/dist/immer.module.js:1065:113: Export 'original' is not defined (1065:113)
1063 |
1064 | export default produce;
> 1065 | export { produce, setAutoFreeze, setUseProxies, applyPatches$1 as applyPatches, createDraft, finishDraft, Immer, original, isDraft, isDraftable, NOTHING as nothing, DRAFTABLE as immerable };
| ^
1066 |
1067 |
The package does bundle correctly when original, isDraft and isDraftable are removed from the export statement. Unlike all other exports, which are defined as var, these three are defined as functions in the module scope in node_modules/immer/dist/immer.module.js, like:
function original(value) {
if (value && value[DRAFT_STATE]) {
return value[DRAFT_STATE].base;
} // otherwise return undefined
}
π Possible Solution
π¦ Context
Iβm converting a CRA app to parcel, however this is withholding me from that.
π» Code Sample
https://github.com/mweststrate/parcel-bug
π Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.12.2 |
| Node | 6.4.1 |
| npm/Yarn | 1.12.3 |
| Operating System | Linux x250 4.18.0-15-generic #16-Ubuntu SMP Thu Feb 7 10:56:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux |
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 16 (3 by maintainers)
Following the lead from @Zero2key, the babel parser seems to be the culprit and just doing this package gets our builds working for now (as a workaround until a fix is introduced):
"@babel/parser": "<7.4.0",Confirmed that adding just the following to
package.jsonworks as a work around (not sure what other things it breaks obviously)Fixed in Babel 7.4.2
Just released parcel v1.12.3 which downgrades Babel to <7.4 while we figure this out.
Also got the same thing with
redux:node_modules/redux/es/redux.js:636:9: Export 'createStore' is not defined (636:9)It triggered by this line in Parcel.
Setting
strictModetonull(which seems to be the default) ortrueworks.falsefails with that error.https://github.com/parcel-bundler/parcel/blob/32f332782e830036c775dc7ad2631b5801719dc3/packages/core/parcel-bundler/src/assets/JSAsset.js#L56-L64
Reproduction using only Babel:
So I guess itβs a Babel bug?
There is no matching babel issue open, correct? (which isnβt strange since 7.4.0 was only released yesterday).
I lock these package version parcel used, @babel/*** < 7.4.0. Now resolve this problem. Seems @babel/***@7.4.0 problem, it have breaking change babel/babel#7646 (comment)
Same issue here:
[...]node_modules/react-router-dom/esm/react-router-dom.js:247:42: Export 'NavLink' is not defined (247:42)