TypeScript Loader for SystemJS
plugin-typescript (current stable version 8.0.0) is a loader plugin for SystemJS that enables the direct `System.import` of TypeScript files. It transpiles `.ts` and `.tsx` files on the fly within the browser or Node.js environment when loaded by SystemJS. This package was the officially supported mechanism for transpiling TypeScript within JSPM 0.17.0 and later, providing immediate compilation and error reporting to the console. It supports TypeScript versions 2.0.0 and higher, with specific older versions (4.0.16 for TS 1.8.1, 2.x.x for TS 1.7.5 and below) required for compatibility. The package's release cadence was tied to the evolution of SystemJS and JSPM, focusing on browser-side transpilation and integration with SystemJS's module loading capabilities.
Common errors
-
Error: (SystemJS) X not found.
cause SystemJS failed to find `plugin-typescript` or `typescript` due to incorrect `map` or `packages` configuration.fixVerify your `SystemJS.config` map and packages entries for 'ts' and 'typescript' point to the correct paths of the installed modules. -
Error: transpiler set to 'ts', however System.import('ts') failed.cause SystemJS could not load the `plugin-typescript` module itself, often due to missing installation or incorrect configuration.fixEnsure `jspm install ts` was run (if using JSPM), or that the manual `SystemJS.config` entries for 'ts' (main, map, meta) are correctly specified and point to `plugin-typescript`'s `lib/plugin.js`. -
TypeScript compile error: Supplied parameters do not match any signature of call target.
cause This is a general TypeScript compilation error indicating a type mismatch or incorrect usage, but it can be exacerbated by incorrect `typescriptOptions` or `tsconfig.json` settings.fixReview the `typescriptOptions` in your `System.config` (or your `tsconfig.json` if `tsconfig: true`) to ensure compiler options like `noImplicitAny`, `strict`, `target`, and `module` are set appropriately for your project and source code.
Warnings
- breaking Major TypeScript version compatibility: plugin-typescript 8.x requires TypeScript 2.0.0+. Older versions of `plugin-typescript` (4.0.16 or 2.x.x) are necessary for TypeScript 1.8.1 and below, respectively.
- gotcha The package is effectively abandoned. The last major update was in 2017 (v8.0.0), and it relies heavily on SystemJS and JSPM, which are less commonly used in modern web development workflows. No further updates or bug fixes are expected.
- breaking Configuration structure for SystemJS changed across major versions of SystemJS and JSPM. Older configuration styles might not work, especially with how packages and transpilers are defined.
- gotcha Resolving `tsconfig.json` path: When `tsconfig: true` is set, `plugin-typescript` attempts to resolve `tsconfig.json` using SystemJS's normal resolution. Incorrect paths or configurations can lead to compiler options not being applied.
Install
-
npm install plugin-typescript -
yarn add plugin-typescript -
pnpm add plugin-typescript
Imports
- Transpiler Configuration
System.config({ transpiler: "ts", packages: { "app": { "defaultExtension": "ts" } } }); - Package-Specific Loader
System.config({ transpiler: "babel", // Use another transpiler by default packages: { "src": { "defaultExtension": "ts", "meta": { "*.ts": { "loader": "ts" } } } } }); - TypeScript Compiler Options
System.config({ typescriptOptions: { module: "system", noImplicitAny: true, tsconfig: true } });
Quickstart
/*
Ensure 'typescript' is installed as a peer dependency:
npm install typescript@^2.4.0
If using JSPM:
jspm install ts
Otherwise, configure SystemJS manually:
*/
SystemJS.config({
packages: {
"ts": {
"main": "lib/plugin.js"
},
"typescript": {
"main": "lib/typescript.js",
"meta": {
"lib/typescript.js": {
"exports": "ts"
}
}
},
"app": {
"defaultExtension": "ts"
}
},
map: {
// Adjust these paths to your installation location
"ts": "./node_modules/plugin-typescript",
"typescript": "./node_modules/typescript"
},
transpiler: 'ts',
typescriptOptions: {
module: "system",
target: "es5",
emitDecoratorMetadata: true,
experimentalDecorators: true,
noImplicitAny: false
}
});
// Example app.ts content (assuming this file exists):
// export class MyClass { constructor(public name: string) {} }
// console.log(new MyClass('Hello from TypeScript!'));
System.import('app/main.ts') // Assuming main.ts is the entry point within the 'app' package
.then(module => {
console.log('Successfully loaded and transpiled main.ts', module);
// You can now interact with exports from main.ts
})
.catch(err => console.error('Error loading TypeScript module:', err));