parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.52k stars 2.26k forks source link

ESM imports not working #9474

Closed LucasC-S closed 10 months ago

LucasC-S commented 10 months ago

Discussed in https://github.com/parcel-bundler/parcel/discussions/9462

Originally posted by **LucasC-S** January 3, 2024 Not sure if this is 100% related to parcel or the packages themselves, but I am trying to use remark-math and rehype-katex with a react app I am using parcel to build. However, when I try and build I get a number of errors where the modules themselves have failed imports. Here is an example: ``` 🚨 Build failed. @parcel/core: Failed to resolve 'devlop' from './node_modules/hast-util-from-html/lib/index.js' ./node_modules/hast-util-from-html/lib/index.js:60:28 59 | > 60 | import {ok as assert} from 'devlop' > | ^^^^^^^^ 61 | import {fromParse5} from 'hast-util-from-parse5' 62 | import {parse, parseFragment} from 'parse5' @parcel/resolver-default: Cannot load file './index' from module 'devlop' ``` The stuff I have found about this from the unified team all indicates that it is a problem with the resolver (eg. this also happens with jest) and not any unified packages. Any help would be greatly appreciated!!
mischnic commented 10 months ago

devlop uses package exports: https://unpkg.com/browse/devlop@1.1.0/package.json

You have to opt into them when using Parcel: https://parceljs.org/features/dependency-resolution/#package-exports

ttodua commented 8 months ago

@mischnic but how to ignore the dynamic imports that might exist in some of the dependency modules? 2024-03-31 22 15 05

for example, those dynamic imports are in i.e. if (special_case) { await import(...);} clause, where our application will never have special_case clause to true and thus I will not need to use those dependencies. how to ignore them?

mischnic commented 7 months ago

@ttodua Add

{
    "alias": {
        "http-proxy-agent": false
    }
}

in your project root's package json.