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 now break on pound sign #3146

Closed snlamm closed 3 years ago

snlamm commented 3 years ago

Bug Report Quick Checklist

Describe the bug

Summary: It looks like snowpack is breaking on file-paths with pounds signs (i.e. #). It breaks on the most recent snowpack v3.3.0 (and v3.2.0). However, it works fine at v3.0.13.

Details: My code relies on an npm dependency which itself relies on an old package called es5-ext. It’s a library to provide shims for ES6. This es5-ext package has the following file structure: es5-ext/array/#/clear.js .

When I run the snowpack build --watch command, however, it’s not able to read past the # in the filepath!

The output I get is:

[12:52:45] [snowpack] dependencies built. [0.00s]
[12:52:45] [snowpack] ! writing to disk...
[12:53:02] [snowpack] + es5-ext/array/#/clear@0.10.53
[12:53:04] [snowpack] Not Found (/_snowpack/pkg/es5-ext.array.)
[12:53:04] [snowpack] Error: Not Found (/_snowpack/pkg/es5-ext.array.)
 at Object.loadUrl (../node_modules/snowpack/lib/index.js:131398:23)
    at async flushFileQueue (../node_modules/snowpack/lib/index.js:131966:28)

I’m running snowpack v3.3.0, with @snowpack/plugin-babel v2.17.

I'm a huge fan of Snowpack. Happy provide any other information!

To Reproduce

  1. npm init snowpack-app --template @snowpack/app-template-react-typescript --use-yarn
  2. yarn add es6-map
  3. in tsconfig.json set strict to false (since es6-map is typed as any)
  4. in src/index.tsx add:
    
    import Map from 'es6-map';

console.log(Map);

5. run `yarn build --watch`
6. See error!

### Expected behavior

I would expect snowpack to use the correct path, along the lines of:

/_snowpack/pkg/es5-ext.array.#.clear.v0.10.53.js


Instead it generates the following, which leads to a 'Not Found' error:

/_snowpack/pkg/es5-ext.array.

drwpow commented 3 years ago

I believe this is expected behavior. In a browser, # marks the end of a URL. So trying to load es5-ext.array.#.clear.v0.10.53.js would result in a browser requesting es5-ext.array.—everything after the hash would be ignored. Because Snowpack’s goal is to maintain parity with the ESM spec, I don’t think we’ll support something that browsers don’t (obviously not including quality of life improvements that don’t conflict with ESM and make writing easier—we’re big fans of those).

snlamm commented 3 years ago

Understood - thanks for taking a look!