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.

require from nodejs and webpack are not similar

See original GitHub issue

Consider 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:closed
  • Created 5 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
timchecommented, Oct 8, 2018

When transpiling for Node.js, can you please try using --esModuleInterop true on the CLI?

0reactions
maxiguecommented, Oct 8, 2018

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 !

Read more comments on GitHub >

github_iconTop 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 >

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