Tree shaking fails with no default export (d3-transition library)
See original GitHub issue🐛 Bug Report
When trying to build a project that includes d3-transition
with --experimental-scope-hoisting
, Parcel crashes with the :
🎛 Configuration (.babelrc, package.json, cli command)
package.json
:
{
"name": "test_repo",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"dependencies": {
"d3-transition": "^1.2.0",
"parcel-bundler": "^1.12.4"
}
}
Command to run: parcel build --experimental-scope-hoisting test.js
🤔 Expected Behavior
The project builds normally with no errors (this happens when the --experimental-scope-hoisting
flag is removed, but should work with the flag, too)
😯 Current Behavior
Parcel crashes with the following error:
yarn parcel build --experimental-scope-hoisting test.js
yarn run v1.19.0
$ /home/jake/temp/test_repo/node_modules/.bin/parcel build --experimental-scope-hoisting test.js
? node_modules/d3-color/src/lab.js does not export 'default'
at replaceExportNode (/home/jake/temp/test_repo/node_modules/parcel-bundler/src/scope-hoisting/concat.js:55:13)
at ReferencedIdentifier (/home/jake/temp/test_repo/node_modules/parcel-bundler/src/scope-hoisting/concat.js:342:20)
at newFn (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/visitors.js:216:17)
at NodePath._call (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/path/context.js:90:31)
at TraversalContext.visitQueue (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/context.js:112:16)
at TraversalContext.visitSingle (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/context.js:84:19)
at TraversalContext.visit (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/context.js:140:19)
at Function.traverse.node (/home/jake/temp/test_repo/node_modules/@babel/traverse/lib/index.js:84:17)
error Command failed with exit code 1.
🔦 Context
Would really like to be able to use tree shaking.
💻 Code Sample
test.js
:
var x = require('d3-transition');
console.log(x)
package.json
and test.js
are all that are required to reproduce the bug.
Steps:
- Place
package.json
andtest.js
in a folder - Install node modules
- Run
parcel build --experimental-scope-hoisting test.js
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | 1.12.4 |
Node | 12.11.1 (also occurs on 10.17.x) |
Yarn | 1.19.0 |
Operating System | Arch Linux |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6
Top Results From Across the Web
Tree-Shaking Problems with Component Libraries - Medium
* Use ES2015 module syntax (i.e. import and export ). * Ensure no compilers transform your ES2015 module syntax into CommonJS modules (this...
Read more >react-d3-speedometer - npm
React library for showing speedometer like gauge using d3.. Latest version: 1.1.0, last published: 2 months ago.
Read more >Update d3 to v4 to enable tree shaking (and reduce the size of ...
Update d3 to v4 to enable tree shaking (and reduce the size of our webpack bundles) All threads resolved!
Read more >Webpack 2 Not Tree Shaking D3.js Properly - Stack Overflow
Tree shaking does appear to work in simple cases on our non-library code. We use "modules": false in our .babelrc in order to...
Read more >Tree-Shaking: A Reference Guide - Smashing Magazine
Tree -shaking” is a must-have performance optimization when bundling ... The source code and libraries you actually use represent the green, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I ran into ‘no default export’ error too (despite it having a default export in the module). Error:
../node_modules/react-share/es/FacebookShareButton.js does not export 'default'
Fixed by upgrading to Parcel V2, removing the
--experimental-scope-hoisting
flag from the parcel build command, and fixing a few issues.1. Upgrade V1 to V2 In terminal ran:
npm uninstall parcel-bundler
From Parcel v2 README:npm install --save-dev parcel@next
2. Remove
--experimental-scope-hoisting
flag from parcel build In package.json, fornpm run build
command, I removed--experimental-scope-hoisting
:"prod": "parcel build public/index.html && cd ./server && tsc && NODE_ENV=production node ./dist/index.js",
3. Fixed issues V1 -> V2 Fixed .png imports error: Added .parcelrc file in the root described in V2 README
npm install --save-dev @parcel/transformer-raw
{ "extends": "@parcel/config-default", "transformers": { "*.png": ["@parcel/transformer-raw"] } }
Fixed this error:
"description": "", "main": "index.js", ^^^^^^^^^^ Did you mean "index.html"?
By following this fix, in my package.json, I removed
"main": "index.js"
.Ran
npm run prod
once again… And tada! It bundled with no errors + epic tree shaking ~12MB bundle to ~1.5MB ! Thank you Parcel!This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.