I've got a very simple, one-file TypeScript project. I'm trying to produce ESM (ES6 module) output for that project.
When I have TypeScript configured to produce ESM output, along the lines of this ...
"compilerOptions": {
"module": "ES2015",
"target": "ES2015",
}
... then I cannot have Jest installed in my project (!?) or I get these errors related to Babel (a transitive dependency of Jest, not something I'm actually using at all in this project):
node_modules/@types/babel__core/index.d.ts:13:20 - error TS2307: Cannot find module '@babel/types'.
13 import * as t from "@babel/types";
~~~~~~~~~~~~~~
node_modules/@types/babel__core/index.d.ts:14:31 - error TS2307: Cannot find module '@babel/parser'.
14 import { ParserOptions } from "@babel/parser";
~~~~~~~~~~~~~~~
node_modules/@types/babel__generator/index.d.ts:9:20 - error TS2307: Cannot find module '@babel/types'.
9 import * as t from "@babel/types";
~~~~~~~~~~~~~~
node_modules/@types/babel__template/index.d.ts:9:31 - error TS2307: Cannot find module '@babel/parser'.
9 import { ParserOptions } from "@babel/parser";
~~~~~~~~~~~~~~~
node_modules/@types/babel__template/index.d.ts:10:54 - error TS2307: Cannot find module '@babel/types'.
10 import { Expression, File, Program, Statement } from "@babel/types";
~~~~~~~~~~~~~~
node_modules/@types/babel__traverse/index.d.ts:10:20 - error TS2307: Cannot find module '@babel/types'.
10 import * as t from "@babel/types";
~~~~~~~~~~~~~~
node_modules/@types/babel__traverse/index.d.ts:30:5 - error TS2411: Property 'scope' of type 'Scope' is not assignable to string index type '(VisitNodeFunction<S, any> & VisitNodeObject<S, any>) | (VisitNodeFunction<S, any> & VisitNodeFunction<S, any>) | (VisitNodeObject<S, any> & VisitNodeObject<S, any>) | (VisitNodeObject<...> & VisitNodeFunction<...>)'.
30 scope?: Scope;
~~~~~
node_modules/@types/babel__traverse/index.d.ts:31:5 - error TS2411: Property 'noScope' of type 'boolean' is not assignable to string index type '(VisitNodeFunction<S, any> & VisitNodeObject<S, any>) | (VisitNodeFunction<S, any> & VisitNodeFunction<S, any>) | (VisitNodeObject<S, any> & VisitNodeObject<S, any>) | (VisitNodeObject<...> & VisitNodeFunction<...>)'.
31 noScope?: boolean;
~~~~~~~
Found 8 errors.
I've tried restricting the TypeScript compiler to only my own code ...
"files": [
"index.ts",
]
I've tried various explicit values for typeRoots
, to try and shut this error up ...
"compilerOptions": {
"module": "ES2015",
"target": "ES2015",
"outDir": "modules",
"typeRoots" : ["node_modules/@types", "node_modules/@babel/types"],
}
Nothing I try works. How can I use "module": "ES2015"
, to avoid transpiling import
statements, without uninstalling Jest or Babel from this project?
Edit: I forgot, here's the full project; it's one TypeScript file, plus a couple configuration files.