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.

Using code from CJS module in ES6 module will try to access non-existing default property

See original GitHub issue

Found a problem with React-leaflet (which is written in ES6) which uses prop-types (CommonJS). The code converted from ES6 module, tries to access default property in the converted CommonJS module, which will fail, as CommonJS module doesn’t export default property:

❯ cat default-problem.js  
import Foo from './foo';

Foo.oneOfType();

❯ cat foo.js              
module.exports = {
  oneOfType: function() {
    return true;
  }
};

❯ java -jar target/closure-compiler-1.0-SNAPSHOT.jar --js foo.js default-problem.js  --process_common_js_modules --module_resolution NODE

var module$foo={oneOfType:function(){return!0}};
var module$default_problem={};
module$foo.default.oneOfType();
//          ^
//          Problem, should bee just module$foo.oneOfType

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ChadKillingsworthcommented, Aug 30, 2017

Well in the case above, it would be fixed with:

import * as Foo from './foo';

That gives you the export object directly.

0reactions
ChadKillingsworthcommented, Oct 12, 2017

I have a fix for this. It’s blocked by #2641

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why doesn't TypeScript complain if I try to import a non ...
I've found that it does complain if I try to use a non-existent default export from a TypeScript module, but not from JavaScript...
Read more >
ECMAScript modules | Node.js v19.2.0 Documentation
The ECMAScript Module Namespace representation of a CommonJS module is always a namespace with a default export key pointing to the CommonJS module.exports ......
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
Firebase JavaScript SDK Release Notes - Google
Fixed issue where clients using Node.js v18 would use the native Blob object, which is incompatible with node-fetch . See Github PR #6705....
Read more >
(node:48512) Warning: Accessing non-existent property 'cd' of ...
Answers related to “(node:48512) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency”.
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