Reputation: 16448
I developed an module and now I want to take this module out of the app and into node_modules. But there is an error error TS2307: Cannot find module 'bipartite-graph'.
where bipartite-graph
is my own module.
This is my systemjs.config.ts
:
SystemJS.config({
packages: {
app: {
main: './app.js',
defaultExtension: 'js'
},
'bipartite-graph': {
main: './bipartite-graph.js',
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
}
},
map: {
app: 'app',
'rxjs': 'node_modules/rxjs',
'bipartite-graph': 'app/bipartite-graph'
}
});
And this is the app.ts
:
import { Subject } from 'rxjs/Subject';
import BipartiteGraph from 'bipartite-graph';
let subject: Subject<boolean> = new Subject<boolean>();
let bg = new BipartiteGraph([35, 50, 40], [45, 20, 30, 30], [[8, 6, 10, 9], [9, 12, 13, 7], [14, 9, 16, 5]]);
const n = 3, m = 4;
let i = 1, j = 1;
while (i <= n && j <= m) {
bg.setAmount(i, j, Math.min(bg.getCapacity(i), bg.getDemand(j)));
bg.setCapacity(i, bg.getCapacity(i) - bg.getAmount(i, j)); bg.setDemand(j, bg.getDemand(j) - bg.getAmount(i, j));
if (bg.getCapacity(i) === 0) {
i = i + 1;
} else {
j = j + 1;
}
}
bg.draw();
The project transpiles and the final app works without errors but Webstorm und tsc throw the error. I imported rxjs
to compare but I can't find a crucial difference. What am I missing? I tried to put the module into node_modules
and changed the path in systemjs.config.ts
but it didn't help. The whole project can be found on project.
Upvotes: 0
Views: 646
Reputation: 3907
The typescript compiler does not find your bipartite-graph
module because it's not reading your systemJS config. You have to add a tsconfig.json
file, if not already there, with the baseUrl and path options set.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"bipartite-graph": ["app/bipartite-graph"],
...other path mappings
}
}
}
more on this topic can be found in the official documentation: https://www.typescriptlang.org/docs/handbook/module-resolution.html
Upvotes: 1