I'm rebuilding my Gulp implementation for compiling, minifying, and compressing TypeScript files into a single bundle using the latest version of Rollup. The new implementation is complete and working and I can trigger it from the Task Runner or using Gulp's file system watcher, and it does exactly what I need it to do.
The problem I'm running into is that in order to get Rollup to see module imports, I had to append the ".ts" extension to the import:
import { something } from "./Module.ts";
Which caused Visual Studio to give this error:
TS2691: (TS) An import path cannot end with a '.ts' extension. Consider importing './Module.js' instead.
The TypeScript compiler seems to ignore the error because when I run the Gulp task, it compiles the TypeScript files as expected. Reading through the GitHub discussions about the ".ts" extension, it seems the recommended solution with the most recent versions of TypeScript is to add a couple of properties to the tsconfig.json
file:
{
"allowImportingTsExtensions": true,
"moduleResolution": "bundler",
"noEmit": true
}
Which caused Visual Studio to give even more errors:
(TS) Unknown compiler option 'allowImportingTsExtensions'.
(TS) Argument for '--moduleResolution' option must be: 'node', 'classic', 'node16', 'nodenext'.
All of this culminates into me not being able to build the project at all. Right now, I'm just in an experimental project I'm going to throw away after I get the new Gulp implementation figured out, but if I apply these changes to my real projects, then I'll never be able to compile them.
What do I need to do to resolve these errors? I tried suppressing TS2691 in the project properties, but it had no effect. I also tried switching from the NuGet TypeScript package, to the npm TypeScript package, and it also had no effect. For reference, I'm using Visual Studio 2022, TypeScript 4.9.5, and Rollup 3.17.3.
error TS5096: Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.
(tsc v5.1.6) – Gallic