问题
Maybe it's a duplicate but I've searched for an hour and haven't found the answer.
I have a node module named a-module
which contains some .ts files (for example a.ts
)
I have another node module b-module
which has a-module
among its dependencies.
I want to import some .ts file from a-module
to b-module
.
In some file within b-module
I write:
import a = require('a-module/a');
console.log(a);
When then I'm trying to compile b-module
with tsc, is says
Cannot find external module 'a-module/a'.
What am I doing wrong?
P.S. I have ArcticTypescript plugin for SublimeText, and seems that it is enough intelligent to find a-module/a
. Why then tsc doesn't manage to locate my file?
P.P.S My file structure looks like that
b-module/
node_modules/
a-module/
a.ts
b.ts
I'm trying to import a.ts
to b.ts
.
回答1:
import a = require('a-module/a');
You need to either use relative paths i.e. ../a-module/a
or declare it for TypeScript explicitly i.e. declare module "a-module/a"
.
来源:https://stackoverflow.com/questions/30525625/typescript-import-ts-file-from-node-module