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.

Default import for React in the library is forcing esModuleInterop flag to be set

See original GitHub issue

Hello, when importing the latest version of the library, during the build we get this error:

$ /Users/xx/work/yyyy/node_modules/.bin/tsc
../poject/node_modules/markdown-to-jsx/dist/index.d.ts:6:8 - error TS1259:
Module '"/Users/xx/work/project/node_modules/@types/react/index"' can only be default-imported using the 'esModuleInterop' flag

6 import React from 'react';
         ~~~~~

This is an issue for us, as its quite troublesome to enable this flag for our huge projet at this point.

Would it be possible to replace the import with import * as React from 'react', which would fix the problem and work everywhere? thank you

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
feedm3commented, May 12, 2021

Nice, it works! Thank you very much for your help!

If someone else comes across this problem, this is what I added to the jest.config.js:

module.exports = {
  moduleNameMapper: {
    'markdown-to-jsx': '<rootDir>/node_modules/markdown-to-jsx/dist/index.module.js',
  },
  transformIgnorePatterns: ['node_modules/(?!(markdown-to-jsx)/)'],
  ...
}
1reaction
probablyupcommented, May 12, 2021

@feedm3 you could probably fix this by using moduleNameMapper in jest config and forcing it to use the ESM bundle

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding esModuleInterop in tsconfig file - Stack Overflow
With flag esModuleInterop we can import CommonJS modules in compliance ... a default property on the exports object in the moment library.
Read more >
Module can only be default-imported using esModuleInterop flag
The error "Module can only be default-imported using esModuleInterop flag" occurs when we try to import a CommonJS module into an ES6 module....
Read more >
esModuleInterop is (should not be) required #1977 - GitHub
Enabling it requires that all other imports where there is no default export to be updated too ( import * as x vs...
Read more >
TSConfig Option: esModuleInterop - TypeScript
a default import like import moment from "moment" acts the same as const moment = require("moment").default. This mis-match causes these two issues: the...
Read more >
Troubleshooting Handbook: tsconfig.json
Selected flags and why we like them: esModuleInterop : disables namespace imports ( import * as foo from "foo" ) and enables CJS/AMD/UMD...
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