Dayjs: ie11 (and other 'es5'-browsers) problem with transpile

Created on 5 Feb 2019  路  10Comments  路  Source: iamkun/dayjs

Dayjs not transpiling down to es5 on version 1.8.4, leaving es6 code in bundle. (the babel/ts webpack config is fine)

1.7.4 is the last known working version

help wanted 鈽笍Bug

Most helpful comment

option 1 pr welcome 馃榿

All 10 comments

@yyynnn Just checked the final code in v1.8.4, everything looks fine in es5.

Any further information please?

I've had the same issue after upgrading from 1.7.8 to 1.8.4, IE11 was logging a SyntaxError because of some arrow function in dayjs.
In dev mode, the error pointed to this line: https://github.com/iamkun/dayjs/blob/dev/src/index.js#L8

This is also happening to us. We are using an ejected version of create react app's webpack build script with minimal changes. The build script isn't able to minify the js. I believe this is because our build script is a little outdated. https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

Newer versions of create react app's webpack build script probably include a loader that transpiles node_modules that are included via the module package.json config option. IDK.

Should that change have been a major version bump?

screen shot 2019-02-05 at 5 03 28 pm

When we remove the "module" property pointing to "./src/index.js" in our local dayjs module, our build process works successfully:

screen shot 2019-02-05 at 5 24 40 pm

With the "module" property, it fails:
screen shot 2019-02-05 at 5 24 33 pm

I think it might be related to https://github.com/iamkun/dayjs/pull/451.

We've added a "module" property in package.json file after v1.8.0+, and pointed to the /src folder which is the source code in es6 with import/export syntax.

This is to made our lib treeshakeable with the help of modern bundle tool like webpack.

This issue is an unexpected behavior, and should be fix in the coming hotfix in a few days.

Just I'm not sure how to fix this, if I point "module" to the compiled es5 code, that makes no sense.

Anyone could help?

@iamkun I think you have two options to fix this:

  1. still transpile the "module" entrypoint, but don't transpile es6 modules. This will let people who support the module entry (webpack et al) use es6 imports with tree shaking and whatnot, but will still run fat arrows, consts, and so on through babel.
  2. publish a new version which removes the module field entirely. Then, publish a new major version with the module field back in and tell people to explicitly pass dayjs through babel themselves. This would mean any webpack users would have to add an exception in their babel loader includes / excludes for dayjs specifically. Not sure what the implication is for other module systems. This would make dayjs harder to use for people, but could have a small benefit in terms of module size.

For what it's worth, I prefer the first option. I could open a PR for this too, if you're interested.

option 1 pr welcome 馃榿

Try hotfix v1.8.5, contains @Tvrqvoise's fix, hope this will help.

Confirmed that v1.8.5 works for me. Thanks @iamkun for the quick updates and the great library!

yeah cool

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LauRocky picture LauRocky  路  5Comments

fundon picture fundon  路  5Comments

vaquel picture vaquel  路  3Comments

g1eny0ung picture g1eny0ung  路  4Comments

sohailalam2 picture sohailalam2  路  4Comments