question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modules not correctly marked as having side effects

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nihakuecommented, Apr 16, 2019

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

1reaction
jkeys-ecg-nmsucommented, Apr 15, 2019

If you’re using modular imports, why wouldn’t you do this?

Auth.configure({...});
Analytics.configure({...});
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found