Comments (24)
UglifyJS can't handle ES6 IIRC
from bss.
That's right Barney.
@smuemd what bundler are you using? If rollup, then bss uses rollup-plugin-buble
for it's browser bundle, so you could use that too to make things work. (you can look at the bss rollup.config.js too)
from bss.
It's a webpack project with standard configuration via spike (https://github.com/static-dev/spike)
@barneycarroll It's actually using ES6 all over the place. bss is the only package where this issue crops up. Emotion works fine for example. But who would want to use that? ;)
from bss.
Oh I see..
I just tried a clean install of spike, and it doesn't complain using bss there.. Is the project one you can share?
Could you try to remove the node_modules folder package-lock.json and do npm install?
Googling for that specific uglify error also returns mostly 2017 results, so perhaps it's an old version causing this?
from bss.
@porsager with spike the js minification only takes place in production mode:
you gotta run
$ npm run prod
I got another hint:
I just took the ./lib
folder and droped it from node_modules/bss
into my local project directory
then:
import b from './lib'
minification worked without errors. Does Rollup give the files some special treatment? I am not too familiar with the tool.
from bss.
Ah sorry, didn't think about that.. I'm reproducing here now too..
I think webpack/babel skips transpiling modules that has a module
entry point field in its package.json 😑
If I delete the module
field in node_modules/bss/package.json and set "main": "lib/index.js"
it works fine... ugh..
from bss.
Pointing main to bss.js and getting rid of the module declaration in package.json works too
what is the module declaration good for anyway?
from bss.
For bss
not that much currently since it only has a single default export, but if it had others, bundlers would use the module entry point to allow for tree-shaking (remove unused code paths).
A side-effect which is nice is that you'll also get ES6 code directly instead of transpiled ES5 which makes sense in cases where you just want to run on ES6 supported clients.
There's some more on the module
field here https://github.com/rollup/rollup/wiki/pkg.module
from bss.
I'm actually curious I can't find anything more about this anywhere.. I don't see why it would make sense for them "not" to transpile the module entry point...
from bss.
interesting question indeed. I also tried theforceAllTransforms
option for uglify-js. it just wont do it.
from bss.
I think I'll keep this open until there's a resolution 😊 If you want to check in with webpack / spike, it's also good to refer here. I might also do that 😉
from bss.
I think the issue lies in the transpilation step before uglify.js.
It's only uglify.es that supports ES6 (also outputs ES6)
from bss.
I'm facing the problem using webpack before, looks like below two line:
Cause babel-loader
to exclude the node_modules
folder, thus also exclude the installed bss module, so bss kept as ES6 module untouched, then lead to the uglify error.
For you own webpack config, solution is remove the exclude rule for babel-loader, but for spike, maybe you should dive into the API to find a way...
from bss.
Ah thanks a lot @futurist
The thing that confuses me is that if I remove the module field and point main to the ES6 entry point it actually does transpile it 🧐
from bss.
@porsager If you use babel-preset-env
, then it's only support transpile below formats:
"amd" | "umd" | "systemjs" | "commonjs" | false, defaults to "commonjs"
https://babeljs.io/docs/en/babel-preset-env.html#modules
The source is here:
Then follow into transform-modules-commonjs
, below line:
seems the plugin skip any isModule
format, then going on to find isModule
definition:
I'm lost in path.node.sourceType === "module"
line...
Looks like module
never be touched by babel-preset-env
?
Edit: I found some wrong thing for above, that "commonjs"
format is for babel target output, so it's not related to this issue, since this issue is for input...
from bss.
@futurist good find!
I opened an corresponding issue in the spike repo
from bss.
@smuemd I looked at the spike issue, and I wasn't sure if my understanding that webpack 4 doesn't have this problem is correct? In that case I also think it would be fine to close this issue..
from bss.
I also faced the problem when using webpack@3, for spike-core
below line caused this issue:
Seems webpack 3 don't support module
field very well...
from bss.
Thanks @futurist .. Do you have an easy workaround for a case like that? Maybe
import b from 'bss/bss'
I hope this is resolved with Webpack 4, but I don't have time to test it right now..
from bss.
Tested I have no issue again for webpack 3 when using import b from 'bss/bss'
, @smuemd could you have a test with spike
?
Maybe can publish module
with a version transpiled, without const
etc, but have export default
just for ES6?
from bss.
@futurist It works! Uglify is not complaining anymore.
What is different now? What did I miss?
from bss.
Hehe...
When you're doing bss/bss
you're importing the bundled & transpiled file ;)
from bss.
Ha. I had no idea. Thought import b from 'bss
would actually do that as specified in package.json main
from bss.
Yeah that's what you would think, but webpack chooses to pick the module
field, and then not include it in it's transpilation pipeline 😔
from bss.
Related Issues (20)
- POJO style question HOT 7
- using bss-react module just for react HOT 10
- Make shorthands a little magic HOT 13
- Allow multiline property value declarations HOT 2
- v2: Extract shorthands into helpers object
- v2: letter-spacing auto px
- Unit interpolation fails in node HOT 1
- convert fractions to percentage values HOT 6
- assign deeper HOT 3
- document how helpers can be used in lean strings HOT 1
- Simple integration width vuejs. HOT 1
- Line Height when given a unitless value doesn't return as expected HOT 3
- SVGs defined in background data urls don't work HOT 1
- Helpers defined with hyphen-case never get called HOT 1
- `$nest` and `$media` not applying style. HOT 3
- Feature Request: Built-in CSS Class Composition HOT 7
- Partial application overload for binary signature methods HOT 9
- Duplicate selector doesn't concat style. HOT 2
- Debug mode makes bugs harder to find HOT 1
- Some functions don't work on Mozilla Firefox lastest update (97.0) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bss.