...
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
...
Обратите внимание, что src/declarations/package_manager/index.js — это сгенерированный JS-файл, использующий импорт ES (и я не могу это изменить). Этот файл косвенно (через другой модуль) импортирован из test/test.ts.
/** @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',
// },
};
[code]npx jest test/test.ts[/code] выдает: [code]... 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 ... [/code] Обратите внимание, что src/declarations/package_manager/index.js — это сгенерированный JS-файл, использующий импорт ES (и я не могу это изменить). Этот файл косвенно (через другой модуль) импортирован из test/test.ts. [code]jest.config.js[/code]: [code]/** @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', // }, }; [/code] [code]tsconfig.json[/code]: [code]{ "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"], } [/code] Как заставить мои тесты .ts использовать файлы .js с импортом внутри этих .js без ошибок?< /п>