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

Missing export with sideEffects: false #9140

Closed
jondlm opened this issue Jul 20, 2023 · 1 comment · Fixed by #9222
Closed

Missing export with sideEffects: false #9140

jondlm opened this issue Jul 20, 2023 · 1 comment · Fixed by #9222

Comments

@jondlm
Copy link
Contributor

jondlm commented Jul 20, 2023

🐛 bug report

I suspect an issue where importing and exporting from the same file, along with sideEffects: false causes Parcel to drop the import as unused. This may be related to #7622 but it seems distinct enough to merit a separate issue.

Minimal repro (repository with full code):

package.json

"sideEffects": false

index.js

import { tokens } from "./tokens";

console.log(tokens.color.blue); // ❌ fails as `tokens.color` is `undefined`

tokens.js

import { color } from "./color";

// 💡 Uncommenting the line below fixes the issue
// console.log(color);

export const tokens = {
  color,
};

// 💡 Alternatively commenting out this line fixes the issue
export { mode } from "./color";

color.js

export const color = {
  blue: "#0196ed",
};

export const mode = "dark";

🎛 Configuration (.babelrc, package.json, cli command)

No notable config beyond sideEffects: false in the package.json.

🤔 Expected Behavior

tokens.color.blue should be defined within index.js.

😯 Current Behavior

Parcel is dropping the color.js module thinking it's unused unless I add a console.log or uncomment the export at the bottom.

💁 Possible Solution

Not sure yet. I'll need to dig into Parcel core to propose something.

🔦 Context

We ran into this bug with one of our internal libraries that is side effect free. It was causing a page to not load correctly.

💻 Code Sample

https://github.com/jondlm/parcel-bug-side-effect-export

🌍 Your Environment

Software Version(s)
Parcel 2.9.2
Node 18.14.0
pnpm 8.6.0
Operating System macOS 13.4.1
@jondlm
Copy link
Contributor Author

jondlm commented Jul 20, 2023

Discovered another way to fix the issue:

export const tokens = {
  color: color,
};

Seems like Parcel can't recognize the color, but can recognize color: color,.

Update: This only happens with parcel serve in development mode. If I build the assets with parcel build the problem doesn't present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant