Modules not correctly marked as having side effects
See original GitHub issueIs your feature request related to a problem? Please describe. Amplify modules have a side effect (registration), but do not provide a sideEffects config in their package.json. The effect of this is that when doing something like this:
import Amplify from '@aws-amplify/core'
import Auth from '@aws-amplify/auth'
import Analytics from '@aws-amplify/analytics'
Amplify.configure({
Auth: {...},
Analytics: {...},
});
when using tree-shaking, Auth will potentially get tree-shaken out of the bundle because it’s only being imported for its side-effect.
Describe the solution you’d like Add sideEffects config to package.json or make modules pure.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Everything you never wanted to know about side effects
A side effect, in an ECMAScript module context, is code that performs some externally-visible behaviour (that is, behaviour which is visible ...
Read more >Determine if importing a Python module causes side effects
The theoretical answer is that you can't determine whether an arbitrary piece of code will have side-effects when run, because if you have...
Read more >Converting JavaScript Scripts to Modules - Documentation
Evaluating a JavaScript program may generate side-effects on the ... Module objects are frozen and there is no way to modify them once...
Read more >Structuring Your Project - The Hitchhiker's Guide to Python
In summary, pure functions are more efficient building blocks than classes and objects for some architectures because they have no context or side-effects....
Read more >Modules, introduction - The Modern JavaScript Tutorial
For instance, if we have a file sayHi.js exporting a function: ... First, if executing a module code brings side-effects, like showing a ......
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 FreeTop 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
Top GitHub Comments
Thanks for the quick responses,
That’s a fine workaround, but the fact remains that Amplify modules claim to be ES6 modules (they set module in package.json) but have effectful imports. Most places in the Amplify documentations tell you to configure via
Amplify.configure
, and there are blog posts high in the Google search results that tell you to do this.If this is not expected to work, maybe Amplify should warn/error when you try it. If it is expected to work, I think it should support (or at least not break when) tree shaking. The way to support it is with “sideEffect” in package.json
If you’re using modular imports, why wouldn’t you do this?