Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using import() fails #1274

Closed
the-spyke opened this issue Feb 27, 2020 · 5 comments
Closed

Using import() fails #1274

the-spyke opened this issue Feb 27, 2020 · 5 comments

Comments

@the-spyke
Copy link

Describe the bug

Node 13.8.0. Using something like import("./file.mjs") inside a .cjs Webpack config file or loader fails with TypeError: Invalid host defined options error. Internally there is ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error. So, there are some issues with using vm module.

The issue was found in babel-loader. Babel supports .mjs config files and loads them with import() internally, but fails to do so when launched by webpack-cli.

What is the current behavior?

To Reproduce

asdf.mjs:

export const x = 42;

webpack.config.cjs:

"use strict";

import("./asdf.mjs")
  .then(m => console.log(typeof m))
  .catch(e => console.log(e));

module.exports = {
  mode: "development"
};

Run with webpack-cli:

$ webpack --config webpack.config.cjs
TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:41:9)
    at Object.<anonymous> (/home/user/app/webpack.config.cjs:3:1)
    at Module._compile (/home/user/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (/home/user/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at WEBPACK_OPTIONS (/home/user/app/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
    at requireConfig (/home/user/app/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
    at /home/user/app/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
    at Array.forEach (<anonymous>)
    at module.exports (/home/user/app/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
    at /home/user/app/node_modules/webpack-cli/bin/cli.js:71:45
    at Object.parse (/home/user/app/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
    at /home/user/app/node_modules/webpack-cli/bin/cli.js:49:8
    at Object.<anonymous> (/home/user/app/node_modules/webpack-cli/bin/cli.js:366:3)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/user/app/node_modules/webpack/bin/webpack.js:156:2)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

Expected behavior

Executing the file with just Node works fine:

$ node webpack.config.cjs
object

Screenshots

Please paste the results of webpack-cli info here, and mention other relevant information

$ webpack info
System:
    OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
  Browsers:
    Chrome: 80.0.3987.122
    Firefox: 73.0.1
  npmPackages:
    webpack: ^4.41.6 => 4.41.6 
    webpack-cli: ^3.3.11 => 3.3.11 
    webpack-dev-server: ^3.10.3 => 3.10.3 

Additional context

Quickly fixing by adding importModuleDynamically to vm invocations changes error to ERR_VM_MODULE_NOT_MODULE. Adding --experimental-vm-modules doesn't help either. Haven't looked further.

@ematipico
Copy link
Contributor

I would not mark it as a bug because we're still lacking compatibility with ESM world. I'd mark it as a feature request for the beta version

@webpack-bot
Copy link

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member

/cc @webpack/cli-team we need test mjs config

@anshumanv
Copy link
Member

WIP here - #1728
Will try to finish it soon

@alexander-akait
Copy link
Member

Close in favor #1622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants