What's even worst, after upgrading I can't run my ...
# webassembly
r
What's even worst, after upgrading I can't run my wasm application with nodeJs anymore.
Node can't load the application with this error:
Copy code
node:internal/modules/cjs/loader:1510
    throw new ERR_INVALID_ARG_VALUE('filename', filename, createRequireError);
          ^

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
    at Function.createRequire (node:internal/modules/cjs/loader:1510:11)
    at i (/home/rjaros/git/kilua/examples/ssr-javalin/build/dist/wasmJs.ssr/productionExecutable/main.bundle.js:2:297641)
    at async /home/rjaros/git/kilua/examples/ssr-javalin/build/dist/wasmJs.ssr/productionExecutable/main.bundle.js:2:281461 {
  code: 'ERR_INVALID_ARG_VALUE'
}
The generated js code in this place looks now like this:
Copy code
e={};f=t.default.createRequire(e.url)
I think the fix for https://youtrack.jetbrains.com/issue/KT-67435 made things even worse.
@Ilya Goncharov [JB]
i
Do you use webpack, and after that you try to run it with Node.js?
r
Yes
I have my own webpack task configured for node.
i
Yes, this case does not work, exactly because webpack processing import.meta
I am not sure that it is feasible to make it work both for browser and nodejs, outputing from one webpack task. But if you have different tasks, I think you can disable import.meta processing for Node.js variant
r
The previous version was almost ok, I could fix issues with a simple regex replace.
If you refer to
module.parser.javascript.importMeta=false
it doesn't help, because I still can't run the app (
SyntaxError: Cannot use 'import.meta' outside a module
).
Fortunately I've managed to workaround the new problem with yet another regular expression:
Copy code
it.replace(
    Regex("""([a-zA-Z]+)=([a-zA-Z]+)\.default\.createRequire\([^\)]+\)(.*)(\{\})\.resolve\(([a-zA-Z]+)\),(.*)\.readFileSync\([a-zA-Z]+\.fileURLToPath\(([a-zA-Z]+)\)\)"""),
    """$1=$2.default.createRequire("file:///foo")$3$1("path").resolve($5),$6.readFileSync($7)"""
)
It changes this js fragment
e={};f=t.default.createRequire(e.url);const n=f("fs"),i=f("url"),r={}.resolve(E),s=n.readFileSync(i.fileURLToPath(r))
into
e={};f=t.default.createRequire("<file://foo>");const n=f("fs"),i=f("url"),r=f("path").resolve(E),s=n.readFileSync(r)
, which is working ok on nodejs.