require with expression not passed to externals function
See original GitHub issueI use webpack for Node projects and want to require
JSON files with Nodes native require
.
This works:
// in order to ignore built-in modules like path, fs, etc.
target: 'node',
externals: [
// require json files with nodes built-in require logic
function(context, request, callback) {
if (/\.json$/.test(request)) {
callback(null, 'commonjs ' + request);
} else {
callback();
}
},
// in order to ignore all modules in node_modules folder
WebpackNodeExternals()
],
require('./package.json');
But this doesn’t work:
require(path.join(process.cwd(), 'package.json'));
It seems it isn’t passed to function(context, request, callback)
. I only get this:
WARNING in ./src/index.ts
Critical dependencies:
44:27-86 the request of a dependency is an expression
@ ./src/index.ts 44:27-86
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Why is Dynamic require(expression) with webpack not working
the solution is with require.context and webpack . I have created webpackConfig.resolve.alias pointing to my appRoot .
Read more >Externals - webpack
Specify the default type of externals as 'node-commonjs' . Webpack will import createRequire from 'module' to construct a require function for loading externals...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >What's New In Python 3.8 — Python 3.11.1 documentation
In this example, the assignment expression helps avoid calling len() twice ... For example, the built-in divmod() function does not accept keyword arguments ......
Read more >13.1.17 CREATE PROCEDURE and CREATE FUNCTION ...
A loadable function can be regarded as an external stored function. ... If you require that expressions passed to a routine be assigned...
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
I also have a use case for this. I think it can be solved like this:
This way worked for me, suggest you have a try. Good luck~
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.