FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

[BUG] Imports break when loaded in an external module and the source. #3076

Open anisebamford opened 3 years ago

anisebamford commented 3 years ago

Bug Report Quick Checklist

Describe the bug

When a React component is imported by an external cjs library and by the es6 source, the import breaks in the external library.

To Reproduce

1: Download the demo https://github.com/bumpusfrancus/snowpack-bug-demo 2: Start the demo with docker-compose up -d. a: The demo's ip address can be obtained with docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker-compose ps | grep "node" | awk '{ print $1}') 3: Go to the IP_ADDRESS:3000/index. The error will appear in the browser console. 4: Go to the IP_ADDRESS:3000/other. The component will be rendered.

Expected behavior

The component should render the same way in both cases.

anisebamford commented 3 years ago

My investigation found that when the third party module is packed, it is placed in an object under a "default" key. The external import then creates another object with a default key holding that object, making the correct path to the component IMPORT_NAME.default.default, but the code is trying to load the component from IMPORT_NAME.default.

anisebamford commented 3 years ago

If you do not use docker, the server is in server/index.js. It uses an absolute path in express static, so that path will need to be updated.

anisebamford commented 3 years ago

This is still an issue in version 3.8.6