require from nodejs and webpack are not similar
See original GitHub issueConsider the following code:
var reduceReducers = require('reduce-reducers');
console.log(reduceReducers.default);
Running this code in node.js with node index.js
, the output is undefined
.
When processed with webpack with the following configuration:
module.exports = {
mode: 'development',
entry: {
index: './index.js'
},
output: {
filename: 'index.js'
}
};
And executed in node.js with node dist/index.js
, then the output is [Function]
.
In the file lib/index.js
, replacing module.exports = exports['default']
with module.exports = exports
makes the whole thing work.
Am I missing something?
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Node.js require webpacked modules - Stack Overflow
Compile for usage in a Node.js-like environment (uses Node.js require to load chunks and not touch any built in modules like fs or...
Read more >Is it Webpack or Node? | Laurie on Tech
Webpack supports a number of different specs, including CommonJS. So require is also valid Webpack syntax. However, Webpack's require is more ...
Read more >Using dynamic require on node targets WITHOUT resolve or ...
I want to dynamically require a module, how node will do it, ... to just avoid webpack to touch a particular require statement...
Read more >How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >Introduction To Webpack with Node.js - Section.io
js, there were no HTML files to add <script> tags. CommonJS (an organisation) came out and introduced Common.js modules and require , which ......
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
When transpiling for Node.js, can you please try using
--esModuleInterop true
on the CLI?Looks like it solves my problem. I have the same format on both sides now. I did not know this option as the project exists since typescript 1 and this was added with typescript 2.7. Thanks for your help !