Код: Выделить всё
npx jest test/test.tsКод: Выделить всё
...
XXX/src/declarations/package_manager/index.js:1
({"Object.":function(module,exports,require,__dirname,__filename,jest){import { Actor, HttpAgent } from "@dfinity/agent";
^^^^^^
SyntaxError: Cannot use import statement outside a module
...
Код: Выделить всё
jest.config.jsКод: Выделить всё
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
preset: 'ts-jest/presets/default-esm', // Use this preset to handle ES modules
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest",{useESM: true}],
},
extensionsToTreatAsEsm: ['.ts'],
// moduleNameMapper: {
// // If you're using non-ESM packages, you might need to map them correctly
// '^(\\.{1,2}/.*)\\.js$': '$1',
// },
};
Код: Выделить всё
tsconfig.jsonКод: Выделить всё
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"lib": ["ES2018", "DOM"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"moduleResolution": "nodenext",
"module": "nodenext",
"skipLibCheck": true,
},
"include": ["src/**/*.ts", "./src/custom.d.ts"],
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... -from-jest