Update (June 2021):
This issue seems to be fixed with the latest versions of parcel2.
See the example above in the Parcel REPL.
What might be happening is that parcel is determining that the Test
class import is actually unused in index.js
, so it's tree-shaking the module.js
entirely.
If you change index.js
to:
import { Test } from "./module.js";
const myInstance = new Test();
You should see that it does not get tree-shaken, and the console.log
statement is executed.
If the code you want to import is under your control, I wouldn't recommend having side effects like that console.log
statements. If it's unavoidable, I think you can tell parcel not to tree-shake either by setting sideEffects: true
in your package.json
(see docs).
(This answer is assuming you are using Parcel 2).