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.

webpack native require doesn't work in windows

See original GitHub issue

I 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:closed
  • Created a year ago
  • Comments:29 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
alexander-akaitcommented, Jun 26, 2022

@eng-dibo Please enable them https://webpack.js.org/configuration/module/#moduleparserjavascriptcommonjsmagiccomments, it was disable by default due perf reasons

1reaction
alexander-akaitcommented, Sep 9, 2022

Feel free to feedback

is there a workaround to use dynamic import with webpack magic comments in Angular projects?

Webpack should not throw erros in this case

Read more comments on GitHub >

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

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