Closed mxmul closed 3 years ago
Thanks for raising. Agree that this isn’t expected, but as a workaround I’d recommend specifying the full extension always. We actually think omitting extensions is an anti-practice, but we do try and resolve them for you just to adapt to how people are familiar with writing code. ESM requires full extensions in the browser, so it’s always good to get in the habit.
There may not be a fix for this anytime soon, as that would involve checking the disk constantly for every file during resolution. To keep Snowpack speedy, we try to keep disk reads/writes to a minimum, and introducing a disk read here would result in noticable slowness in Snowpack (speaking from experience—I recently tried an experiment with this).
@drwpow I have a PR ready that should fix this, and doesn't add any additional file operations: https://github.com/snowpackjs/snowpack/pull/3315
@drwpow I have a PR ready that should fix this, and doesn't add any additional file operations: #3315
Ah I missed that linked PR! Sorry; taking a look now! 👀
Bug Report Quick Checklist
Describe the bug
If you have a JS/TS file named like
styles.css.ts
, snowpack isn't able to resolve it when the import specifier looks likeimport './styles.css'
.It appears that snowpack's module resolution algorithm short-circuits, and it assumes this import must refer to a
styles.css
file on disk. There is no such file, so the dev server 404s.To Reproduce
npm init snowpack-app --template @snowpack/app-template-blank
apply this diff:
styles.css.proxy.js
Expected behavior
Snowpack should resolve these imports to the
.css
file on disk if one exists. If there is no such file, it should assume this is a JS/TS import with an implicit file extension and try to resolve to a.css.js
or.css.ts
file on disk.Anything else?
This came up as an issue when trying to write a snowpack plugin for vanilla-extract; that library uses
.css.ts
files and it's documentation suggests importing those files from TS likeimport { className } from './styles.css'
.Importing the files with an explicit
.css.js
extension is a viable workaround, but this behavior feels like a bug in Snowpack.