Comments (3)
Yeah, not sure how we can solve it, because we need import.meta.url
for https://nodejs.org/api/module.html#modulecreaterequirefilename, I want to say it is a limitation, why do not use createRequire
in code?
from webpack.
I am unable to use createRequire
, because I'd need import.meta.url
for it:
Input:
const path = require('path');
module.exports = {
entry: './src/index.js',
devtool: 'eval-source-map',
target: 'node18',
externalsPresets: { node: true },
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
experiments: {
outputModule: true,
},
optimization: {
minimize: false,
},
};
import * as module from 'node:module';
const customRequire = module.createRequire(import.meta.url);
customRequire('something');
Output:
/*
* ATTENTION: An "eval-source-map" devtool has been used.
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
/******/ var __webpack_modules__ = ({
/***/ 590:
/***/ (() => {
eval("\n;// CONCATENATED MODULE: external \"node:module\"\nconst external_node_module_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)(\"node:module\");\n;// CONCATENATED MODULE: ./src/index.js\n\n\nconst customRequire = external_node_module_namespaceObject.createRequire(\"file:///home/projects/github-qjzdxl/src/index.js\");\ncustomRequire('something');\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNTkwLmpzIiwibWFwcGluZ3MiOiI7O0FBQUEsTUFBTSxvQ0FBNEIsb0U7O0FDQUk7O0FBRXRDLHNCQUFzQixrREFBb0IsQ0FBQyxrREFBZTtBQUMxRCIsInNvdXJjZXMiOlsid2VicGFjazovL2dldHRpbmctc3RhcnRlZC11c2luZy1hLWNvbmZpZ3VyYXRpb24vZXh0ZXJuYWwgbm9kZS1jb21tb25qcyBcIm5vZGU6bW9kdWxlXCI/YTRiNSIsIndlYnBhY2s6Ly9nZXR0aW5nLXN0YXJ0ZWQtdXNpbmctYS1jb25maWd1cmF0aW9uLy4vc3JjL2luZGV4LmpzPzg4YjciXSwic291cmNlc0NvbnRlbnQiOlsiY29uc3QgX19XRUJQQUNLX05BTUVTUEFDRV9PQkpFQ1RfXyA9IF9fV0VCUEFDS19FWFRFUk5BTF9jcmVhdGVSZXF1aXJlKGltcG9ydC5tZXRhLnVybCkoXCJub2RlOm1vZHVsZVwiKTsiLCJpbXBvcnQgKiBhcyBtb2R1bGUgZnJvbSAnbm9kZTptb2R1bGUnO1xuXG5jb25zdCBjdXN0b21SZXF1aXJlID0gbW9kdWxlLmNyZWF0ZVJlcXVpcmUoaW1wb3J0Lm1ldGEudXJsKTtcbmN1c3RvbVJlcXVpcmUoJ3NvbWV0aGluZycpO1xuIl0sIm5hbWVzIjpbXSwic291cmNlUm9vdCI6IiJ9\n//# sourceURL=webpack-internal:///590\n");
/***/ })
/******/ });
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval-source-map devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__[590]();
/******/
As you can see, this still leads to import.meta.url
being used inside of eval
and the actual import.meta.url
being replaced with a hard-coded filepath.
from webpack.
I see...
from webpack.
Related Issues (20)
- Eager consumption of a shared module if there are several versions of the module
- Code splitting single JS files based on which functions are used by which parent components or files. HOT 1
- PreOrderIndex and PostOrderIndex are incorrect in some cases
- Exported object names not minified since 5.79 HOT 2
- Empty file emitted for `await import('crypto')` in a dependency despite resolve.fallback.crypto = false
- Different window.open in an async call behaviour between Webpack 4 & Webpack 5 HOT 4
- Add null check to avoid `TypeError: Cannot read properties of undefined (reading 'call')` HOT 2
- this.importModule broken in esm packages HOT 7
- How does one dynamically import optional dependencies?
- Warning appeared after updating node version HOT 1
- Allow aliases to be resolved without an extra slash (#14370) HOT 3
- Cannot read properties of undefined (reading 'Z')
- Cannot read property 'name' of undefined HOT 1
- when setting `optimization.providedExports` to false, outputModule wouldn't generate export statement HOT 3
- Bundled code is attempting to export before importing (ERROR: _common__WEBPACK_IMPORTED_MODULE_1__ is undefined)
- Export warnings while exporting CSS using Webpack 5 HOT 5
- Clarification on the Use of require Parameter in require.ensure Callback function HOT 3
- Deduping ESM and CJS versions of the same package HOT 2
- Destructured values from an imported namespace are mangled and returning undefined
- Chunk's `auxiliaryFiles` set contains `undefined` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack.