From 75510e60193d694e35807f4c99749fc5a943cb11 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 20 Sep 2022 23:23:56 +0200 Subject: [PATCH] [K/Wasm] Fix incompatibilities with webpack. * Webpack doesn't support "node:" prefix out of the box, so we can just ignore it. * Use a proper way to get a path to the script's dir. #KT-53790 Fixed --- .../src/org/jetbrains/kotlin/backend/wasm/compiler.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt index e1cd2076ed0..8e57e9c4f02 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt @@ -134,13 +134,14 @@ fun generateJsWasmLoader(wasmFilePath: String, externalJs: String): String = let wasmInstance; let require; // Placed here to give access to it from externals (js_code) if (isNodeJs) { - const module = await import('node:module'); - require = module.createRequire(import.meta.url); + const module = await import(/* webpackIgnore: true */'node:module'); + require = module.default.createRequire(import.meta.url); const fs = require('fs'); const path = require('path'); const url = require('url'); - const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); - const wasmBuffer = fs.readFileSync(path.resolve(__dirname, './$wasmFilePath')); + const filepath = url.fileURLToPath(import.meta.url); + const dirpath = path.dirname(filepath); + const wasmBuffer = fs.readFileSync(path.resolve(dirpath, '$wasmFilePath')); const wasmModule = new WebAssembly.Module(wasmBuffer); wasmInstance = new WebAssembly.Instance(wasmModule, { js_code }); }