Closed alejandroclaro closed 4 years ago
same here
Different line numbers, but same error:
TypeError: runtime.unstable_shouldLoadAsEsm is not a function
at jasmine2 (/node_modules/@jest/core/node_modules/jest-jasmine2/build/index.js:188:25)
at /node_modules/@jest-runner/electron/node_modules/jest-runner/build/runTest.js:385:24
at Generator.next (<anonymous>)
at asyncGeneratorStep (/node_modules/@jest-runner/electron/node_modules/jest-runner/build/runTest.js:161:24)
at _next (/node_modules/@jest-runner/electron/node_modules/jest-runner/build/runTest.js:181:9)
at jasmine2 (node_modules/@jest/core/node_modules/jest-jasmine2/build/index.js:188:25)
at Server.emit (node_modules/event-pubsub/es5.js:74:21)
at Server.gotData (node_modules/node-ipc/dao/socketServer.js:194:14)
My temporary fix is to patch / replace const esm = runtime.unstable_shouldLoadAsEsm(xxx);
with const esm = false;
in node_modules/jest-jasmine2/build/index.js
(which could be a subfolder of node_modules/@jest/core/
, depending on your local NPM/Yarn setup)
Source code references:
There are many ways to implement the aforementioned patch, but as this is a temporary measure, FYI I simply wrote a quick postinstall
script in my package.json
to patch jest-electron-runner
until it is upgraded to the latest Jest 25.4.x
:
"patchElectronJestJasmine": "node scripts/replace-in-file.js './node_modules/@jest/core/node_modules/jest-jasmine2/build/index.js' 'const esm = runtime.unstable_shouldLoadAsEsm' 'const esm = false; // runtime.unstable_shouldLoadAsEsm'",
...where scripts/replace-in-file.js
is:
const path = require('path');
const fs = require('fs');
const args = process.argv.slice(2);
const filePath = path.join(process.cwd(), args[0]);
let fileStr = fs.readFileSync(filePath, { encoding: "utf8" });
const regex = new RegExp(args[1], "g");
fileStr = fileStr.replace(regex, args[2]);
fs.writeFileSync(filePath, fileStr, { encoding: "utf8" });
Quick and dirty :)
I founded a way to fix this: Yarn: https://classic.yarnpkg.com/en/docs/selective-version-resolutions/ Npm: https://github.com/rogeriochaves/npm-force-resolutions
In your package.json, add:
"resolutions": {
"@jest-runner/electron/jest-haste-map": "^25.4.0",
"@jest-runner/electron/jest-mock": "^25.4.0",
"@jest-runner/electron/jest-runner": "^25.4.0",
"@jest-runner/electron/jest-runtime": "^25.4.0",
"@jest-runner/electron/jest-util": "^25.4.0"
}
And run yarn install
.
This even fixes the console error #54
It's a temporary way until jest-electron-runner
is updated.
https://github.com/facebook-atom/jest-electron-runner/pull/62 should have fixed it! sorry about the breakage
published @jest-runner/electron@3.0.0
It's working after recent Jest updates. I get the following error: