Closed mahmoudelbadrywork closed 1 year ago
Second I'm having a problem using the
preact-router.module.js
as is from the dist folder in an ES Modules project that uses eleventy to copy the files fromnode_modules
to another directory
This is not a viable way to use any library with dependencies, unfortunately. Libraries distributed upon NPM do so knowing they can take advantage of the module resolution mechanisms that are built into all modern platforms. This makes them unsuitable for the web.
You'll either want to rebundle your deps yourself (to remove the need for module specifiers altogether) or use one of the many CDNs that have this figured out already. Usually they end up rewriting specifiers, so import ... from 'preact'
becomes import ... from 'https://example-cdn.com/preact'
.
You will need to change import xyz from "package"
to import xyz from "./package.js"
For example, my router.js file looks like this
Hello, First Thanks for your work on Preact and Preact Router Second I'm having a problem using the
preact-router.module.js
as is from thedist
folder in an ES Modules project that uses eleventy to copy the files fromnode_modules
to another directory so When I import the Router using the following lineit gives me the following error in the console:
This is due to the following line in the
preact-router.module.js
file:Is there something I'm missing here to use the ES Module as is without any modification or build step