While researching how to import jspm packages into typescript, I noticed that most examples assumed the use of SystemJS for loading and interpreting them in the browser. However, I prefer using tsc
to compile commonjs modules and only import the js code, as it seems to be a more general and error-resistant approach.
My directory structure is as follows:
src/index.ts
jspm_packages/...
config.js
tsconfig.json
The contents of tsconfig are:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"rootDir": "src",
"outDir": "target/app",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true
},
"exclude": [
"jspm_packages",
"node_modules",
"typings",
"target"
]
}
For testing purposes, I installed Angular 2 with jspm install npm:angular2
and attempted to import it in my index.ts
using
import { bootstrap } from 'angular2/platform/browser';
However, when running tsc
, I encountered the error:
src/index.ts(1,27): error TS2307: Cannot find module 'angular2/platform/browser'.
I'm curious if there's a way to make jspm packages known to typescript. I've tried various approaches such as removing jspm_packages from the tsconfig exclude list, switching to node module resolution, or systemjs module generation. Perhaps there's a specific combination I haven't discovered yet. Any suggestions on what to try next?