Using code from CJS module in ES6 module will try to access non-existing default property
See original GitHub issueFound 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:
- Created 6 years ago
- Reactions:1
- Comments:20 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well in the case above, it would be fixed with:
That gives you the export object directly.
I have a fix for this. It’s blocked by #2641