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

shimMissingExports will cause error when treeshake and preserveModules both is true #4884

Closed
EAGzzyCSL opened this issue Feb 28, 2023 · 4 comments · Fixed by #4971
Closed

Comments

@EAGzzyCSL
Copy link

Rollup Version

v3.17.3

Operating System (or Browser)

macOS Ventura 13.2.1

Node Version (if applicable)

v16.13.0

Link To Reproduction

https://stackblitz.com/edit/rollup-case-shim

Expected Behaviour

build successfully with shim warning

by the way:

  1. turn off treeshake or preserveModules will build ok.
  2. it's works in rollup REPL

Actual Behaviour

(!) Missing export "bar" has been shimmed in module "src/foo.js".
[!] TypeError: Cannot read properties of undefined (reading 'exports')
    at Chunk.setUpChunkImportsAndExportsForModule (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/shared/rollup.js:16252:27)
    at Chunk.link (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/shared/rollup.js:15618:18)
    at Bundle.generateChunks (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/shared/rollup.js:17175:19)
    at async Bundle.generate (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/shared/rollup.js:17075:28)
    at async eval (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/shared/rollup.js:25190:27)
    at async catchUnfinishedHookActions (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/shared/rollup.js:24328:20)
    at async Promise.all (index 0)
    at async build (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/bin/rollup:1552:5)
    at async runRollup (file:///home/projects/rollup-case-shim/node_modules/rollup/dist/bin/rollup:1658:21)
@EAGzzyCSL
Copy link
Author

Turns out it does fail in the REPL as well: https://rollupjs.org/repl/?version=3.17.3&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyaW1wb3J0JTIwJTdCZm9vJTdEJTIwZnJvbSUyMCcuJTJGZGVwLmpzJyU1Q25jb25zb2xlLmxvZyhmb28pJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjIlMjIlMkMlMjJpc0VudHJ5JTIyJTNBZmFsc2UlMkMlMjJuYW1lJTIyJTNBJTIyZGVwLmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMm91dHB1dCUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTJDJTIycHJlc2VydmVNb2R1bGVzJTIyJTNBdHJ1ZSU3RCUyQyUyMnNoaW1NaXNzaW5nRXhwb3J0cyUyMiUzQXRydWUlN0QlN0Q=

Thank you for your reply 😀.

I have find an interesting thing is that some times it will work in REPL,like this: https://rollupjs.org/repl/?version=3.17.3&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMiUyRiUyRiUyMFRSRUUtU0hBS0lORyU1Q25pbXBvcnQlMjAlN0IlMjBiYXIlMjAlN0QlMjBmcm9tJTIwJy4lMkZmb28uanMnJTNCJTVDbiU1Q25jb25zb2xlLmxvZyhiYXIpJTNCJTIwJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJleHBvcnQlMjBjb25zdCUyMGZvbyUyMCUzRCdmb28nJTVDbmNvbnNvbGUubG9nKCcnKSUyMiUyQyUyMmlzRW50cnklMjIlM0FmYWxzZSUyQyUyMm5hbWUlMjIlM0ElMjJmb28uanMlMjIlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTIyb3V0cHV0JTIyJTNBJTdCJTIyZm9ybWF0JTIyJTNBJTIyZXMlMjIlMkMlMjJwcmVzZXJ2ZU1vZHVsZXMlMjIlM0F0cnVlJTdEJTJDJTIyc2hpbU1pc3NpbmdFeHBvcnRzJTIyJTNBdHJ1ZSUyQyUyMnRyZWVzaGFrZSUyMiUzQXRydWUlN0QlN0Q=

The most surprising is the code of both case is nearly identical. I have also find if there is any code in dep.js(such as console.log),it will work. REPL: https://rollupjs.org/repl/?version=3.17.3&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyaW1wb3J0JTIwJTdCZm9vJTdEJTIwZnJvbSUyMCcuJTJGZGVwLmpzJyU1Q25jb25zb2xlLmxvZyhmb28pJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJjb25zb2xlLmxvZygpJTIyJTJDJTIyaXNFbnRyeSUyMiUzQWZhbHNlJTJDJTIybmFtZSUyMiUzQSUyMmRlcC5qcyUyMiU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJvdXRwdXQlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMnByZXNlcnZlTW9kdWxlcyUyMiUzQXRydWUlN0QlMkMlMjJzaGltTWlzc2luZ0V4cG9ydHMlMjIlM0F0cnVlJTdEJTdE

@lukastaegert
Copy link
Member

Fix at #4971

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4971 as part of rollup@3.21.4. You can test it via npm install rollup.

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

Successfully merging a pull request may close this issue.

3 participants