preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.02k stars 155 forks source link

match.js:55 Uncaught TypeError: (0 , Router.exec) is not a function #347

Closed kulak closed 4 years ago

kulak commented 4 years ago

I have tried rollupjs approach that's not path frequently taken and I used preact-cli generated TypeScript as a starting point. So, the issue might be caused by rollupjs.

When I include Link I get this error:

match.js:55 Uncaught TypeError: (0 , Router.exec) is not a function

I created a demo project to replicate this error with detailed exception provided in README: https://github.com/Kulak/preactRouterRollupExample

My tsconfig file already includes option

"esModuleInterop": true

Does anyone have any idea?

kulak commented 4 years ago

I have noticed that while react-router distributes both es and non-es versions here: https://unpkg.com/browse/preact-router@3.1.0/

match.js is included without es version, without package.json file referencing it. Could that be a problem?

aguilera51284 commented 4 years ago

i have the same error, i try to says this in slack but.... nobody answered me :(

marvinhagemeister commented 4 years ago

@aguilera51284 I can't find any message thread related to that for the past weeks in slack.

@Kulak Thank you so much for the repo. That way I can easily reproduce the described issue. I had a closer look and the error is caused by a bug in @rollup/plugin-commonjs (formely known as rollup-plugin-commonjs. In our case we're exporting the code like this:

class Foo {
  // ...
}

Foo.baz = 42

const bar = () => null;

export { Foo, bar };
export default Foo;

When rollup sees someone using a commonjs import like we do in match.js that is distributed on npm, rollup wrongly throws away all non-default exports.

const MyFoo = require("./Foo");

// What rollup actually exports
class Foo() {...}

// What should be correct exports instead
{
  default: Foo,
  Foo,
  bar,
}

I'm afraid we can't fix that issue on our end. The rollup team is pretty amazing when it comes to fixing these things so the best chance to get this resolved is to file an issue in their tracker :+1:

webyom commented 4 years ago

@marvinhagemeister I don't think this is a rollup issue, as match is a cjs module which depends on exec of main module, but exec isn't exported in main cjs module.