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

Published node module not ES5 #746

Closed
jasperkuperus opened this issue Apr 6, 2021 · 16 comments
Closed

Published node module not ES5 #746

jasperkuperus opened this issue Apr 6, 2021 · 16 comments
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@jasperkuperus
Copy link

jasperkuperus commented Apr 6, 2021

Environment

  • Linaria version: 3.0.0-beta.1
  • Bundler (+ version): Webpack 5.26.0
  • Node.js version: 12.16.2
  • OS: macOS

Description

First off, I really like this lib. Keep up the good work.

The version of linaria that's published to npm isn't transpiled down to ES5 properly. I noticed due to spread operators, originating from @linaria/core, landing in my bundle.js that made older browsers crash. I guess the module should be properly transpiled to ES5 before publishing it to npm.

While investigating, I noticed that I was on this 3.0.0 beta. So I figured to downgrade to 2.1.0, which I saw in the releases. But it didn't allow me... Must be some renamed packages? Couldn't find any instructions on this. -> I managed to get 2.1.0 installed, but same issue there with spread operators in published package.

Reproducible Demo

n/a

@jasperkuperus jasperkuperus added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Apr 6, 2021
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Apr 6, 2021
@Anber
Copy link
Collaborator

Anber commented Apr 11, 2021

Hi @jasperkuperus!

Fixed and will be released in 3.0.0-beta.2

@Anber Anber closed this as completed Apr 11, 2021
@jasperkuperus
Copy link
Author

Hi @Anber . Thanks for the quick reply! It looks like the spread operators are gone indeed. But now I'm running into the same issue with arrow functions:

Screenshot 2021-04-13 at 10 01 13

This unfortunately also lets my older browsers crash :( Can we reopen this?

@Anber
Copy link
Collaborator

Anber commented Apr 13, 2021

Ouch!
I completely forgot that there are browsers without the support of arrow functions :)

@Anber Anber reopened this Apr 13, 2021
@Anber
Copy link
Collaborator

Anber commented Apr 13, 2021

btw, do you know that property-based interpolation for styled is not working in such old browsers? You still can use css and styled, but property-based interpolation requires css variables.

@jasperkuperus
Copy link
Author

Yes, I'm well aware. I think I can get away with that and for these browsers I aim for graceful degradation. Some styling that didn't get picked up by the browser is OK, but the app crashing is not 😊

@Anber
Copy link
Collaborator

Anber commented Apr 13, 2021

Ok! I'll release a fix in a couple of days.

@jasperkuperus
Copy link
Author

jasperkuperus commented Apr 13, 2021

Perfect, again thanks for the fast/adequate response! Please keep me posted on when you publish it!

@Anber
Copy link
Collaborator

Anber commented Apr 14, 2021

In order to avoid future reopenings, could you please replace these files in your local node_modules and confirm, that everything is ok? :)

@jasperkuperus
Copy link
Author

jasperkuperus commented Apr 15, 2021

Still has the same issue. So, as I've set webpack to target: es5, it apparently picks up the source code from core/esm, which still has arrow functions.

Quick and maybe silly question. Why not add a transpiler like Babel and make sure it transpiles the code before publishing it? That way you can keep using your favourite language constructs and users of the library are free to use it in any environment. And more importantly, if you forget to take this into account one day and accidentally write an arrow function, you won't break anyone's app 😊

@Anber
Copy link
Collaborator

Anber commented Apr 15, 2021

It's transpilled: to es3 in lib and to es5 in esm. If you set webpack target to es5, webpack takes es5 version of code with arrows, const and imports/exports. However, there was a problem with the compilation target in babel, which excludes ie11, and the code itself has a few functions that weren't implemented in IE11. I hope, that #750 fixes it.

@jasperkuperus
Copy link
Author

Ah, pardon me for thinking it's not transpiled. I'll be happy to test it when it's published!

@Anber Anber closed this as completed in 922df95 Apr 15, 2021
@jasperkuperus
Copy link
Author

@Anber When are you going to publish this to npm? I'd like to test it 😊

@Anber
Copy link
Collaborator

Anber commented Apr 20, 2021

@jasperkuperus done!

@jasperkuperus
Copy link
Author

jasperkuperus commented Apr 22, 2021

It's transpilled: to es3 in lib and to es5 in esm. If you set webpack target to es5, webpack takes es5 version of code with arrows, const and imports/exports. However, there was a problem with the compilation target in babel, which excludes ie11, and the code itself has a few functions that weren't implemented in IE11. I hope, that #750 fixes it.

Tested 3.0.0-beta.3, it still picked up esm/. But considering your quote here, I forced Webpack to pick up lib/ and that fixed all my issues. No clue if this is the proper way to force loading lib/ in stead of esm/, but I ended up doing this:

  resolve: {
    alias: {
      '@linaria/core': path.join(__dirname, './node_modules/@linaria/core/lib'),
    },
  },

So consindering your intended approach @Anber , of having es3 in lib/, this issue is fixed 😊 Thanks a lot!

@Anber
Copy link
Collaborator

Anber commented Apr 24, 2021

Hi @jasperkuperus!

Take a look at that config option https://webpack.js.org/configuration/resolve/#resolvemainfields
If you want to support old browsers, you probably need to specify main as a first option.

@jasperkuperus
Copy link
Author

jasperkuperus commented Apr 26, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

No branches or pull requests

2 participants