I have an exported class
in my working Angular2 app using ES6 module:
//File = init.todos.ts
export class Init {
load() {
...
}
}
I'm importing this class from another component via :
//File = todo.service.ts
import { Init } from './init.todos'
It works as expected.
However if I change the loading mechanism to commonjs :
//File = init.todos.ts
export class Init {
load() {
...
}
}
module.exports.Init = Init;
Requiring it:
//File = todo.service.ts
var Init = require(./init.todos);
— I get those errors :
...myApp/src/app/todo.service.ts
(4,13): Cannot find name 'require'.)
...myApp/src/app/todo.service.ts (12,14):
Property 'load' does not exist on type 'TodoService'.)
Question:
How can I also load commonjs modules using require
?
Tsconfig.json:
{
compileOnSave: false,
compilerOptions: {
outDir: ./dist/out-tsc,
baseUrl: src,
module: system,
sourceMap: true,
declaration: false,
moduleResolution: node,
emitDecoratorMetadata: true,
experimentalDecorators: true,
target: es5,
typeRoots: [
node_modules/@types
],
lib: [
es2016,
dom
]
}
}
Here are the config files :