webpack native require doesn't work in windows
See original GitHub issueI want to natively require modules without using webpack requiring mechanism, i.e keeping require(..) as it without touch.
to achieve my goal I created a file called native-require.js with this content
module.exports = require;
and in webpack.config.js
module: {
noParse: /\/native-require.js$/,
}
now, in my script file I do:
let filePath = resolve(__dirname, `../config/file.js`);
let content = nativeRequire(filePath);
console.log(content)
it works fine in Linux but in windows I got the error Cannot find module 'D:\Downloads\config\file.js'
I also tried to remove the file extension from filePath
I don’t want to lock my project to webpack-only using, I need my project to be able to run without webpact (for example using ts-node)
so I don’t want to use webpack-specific variables such as __webpack_require__
Issue Analytics
- State:
- Created a year ago
- Comments:29 (15 by maintainers)
Top Results From Across the Web
node.js - webpack native require doesn't work in windows
I want to natively require modules without using webpack requiring mechanism, i.e keeping require(..) as it without touch.
Read more >Module Methods - webpack
This section covers all methods available in code compiled with webpack. When using webpack to bundle your application, you can pick from a...
Read more >Installation | webpack
This guide goes through the various methods used to install webpack. Prerequisites. Before we begin, make sure you have a fresh version of...
Read more >Development - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >To v5 from v4 - webpack
Upgrade webpack to 5 · Clean up configuration · Need to support an older browser like IE 11? · Cleanup the code ·...
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 Free
Top 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

@eng-dibo Please enable them https://webpack.js.org/configuration/module/#moduleparserjavascriptcommonjsmagiccomments, it was disable by default due perf reasons
Feel free to feedback
Webpack should not throw erros in this case