question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent module resolution with typescript under node/web

See original GitHub issue
  • match-sorter version:2.2.1
  • node version:8.2.1
  • npm (or yarn) version:yarn 1.0.2/npm 5.8.0

What you did: Basically trying to use match-sorter with typescript in browser and node.

What happened:

An error is thrown when trying to test a file that imports match-sorter.

Reproduction repository:

https://github.com/yakirn/matchsorter-ts

Problem description: I used a very basic setup. create-react-app with typescript as described here. I added basic match-sorter code to App.tsx. When running using yarn start a browser pops up and everything works as expected. But when trying to test the component using yarn test an error is thrown: Error: Uncaught [TypeError: match_sorter_1.default is not a function]

Suggested solution: I’m no sure why, but import matchSorter from 'match-sorter'; works in the browser but not in node. while import * as matchSorter from 'match-sorter'; works in node, but not in the browser.

I would love to help solve this issue, and later add types definition, but I guess there’s a problem with the bundler of this project, and I can use some guidance. Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
kentcdoddscommented, Mar 28, 2018

I’m guessing this is happening because node is resolving your require/import to the package.json main field and webpack is resolving your require/import to the package.json module field. These are slightly different to facilitate an improved experience for people using CommonJS and UMD. I’m planning on changing this, and that will be a breaking change which should have fairly minimal impact so hopefully I can get to it soon.

3reactions
kentcdoddscommented, Jul 19, 2019

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript ES modules incompatible with browser and Node.js
Typescript is incompatible with ECMAScript modules, as implemented in browsers and Node.js (the two most common ES runtimes).
Read more >
Common TypeScript module problems and how to solve them
Enabling the compiler module resolution tracing in TypeScript can provide insight in diagnosing and solving problems.
Read more >
Documentation - Module Resolution - TypeScript
This resolution strategy attempts to mimic the Node.js module resolution mechanism at runtime. The full Node.js resolution algorithm is outlined in Node.js ......
Read more >
node.js - TypeScript won't resolve module when import is used
I have written more extensively about choosing between internal and external modules in TypeScript. The bottom line is choose only one.
Read more >
Announcing TypeScript 4.7 RC - Microsoft Developer Blogs
This should provide newer ES module functionality from Node.js ... This also means paths resolve differently between .ts files that are ES ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found