I am currently working on a Typescript 2.0 project that utilizes Common JS modules and System JS loader. My IDE of choice is Visual Studio code. I am encountering a challenge with integrating an external library (filesaver JS) into my project.
After installing both the library and the type definition via npm, I can see them in my node_modules and node_module/@types directories respectively.
My main issue arises when trying to reference (import) the filesaver saveAs function in my TypeScript code within a function that is responsible for saving a blob (an object converted to a JSON string).
Despite multiple attempts with various import options, I have not been successful. I consistently encounter errors such as 'index.d.ts' is not a module or 'module not found'.
Here are the import statements I have tried:
import filesaver = require('FileSaver'); //error: index.d.ts is not a module
import {FileSaver} from 'file-saver'; //error: cannot find module file-saver
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "es2015", "dom"],
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"typeRoots": [
"./node_modules/@types",
"./node_modules"
],
"types": [
"node"
]
},
"exclude": [
"node_modules",
"dist",
"src"
],
"compileOnSave": false
}