1

This problem has long bothered me but I am at a loss as to why. I seem to always be fighting with node_modules. This isn't a @types issue. I am trying to use TypeScript NPM Libraries which already have types.

A great example of this is font awesome. I follow the guide.

npm install @fortawesome/fontawesome-svg-core --save

It tell me that I should then go ahead and configure it using this syntax.

import { library, dom } from '@fortawesome/fontawesome-svg-core';

To which TypeScript informs me that this isn't a module.

I always have to resort to dirty paths like this:

import { library, dom } from '../node_modules/@fortawesome/fontawesome-svg-core/index';

Why does this work for everyone apart from myself?

Here is my tsconfig

{
    "compileOnSave": true,
    "compilerOptions": {
        "sourceMap": true,
        "allowJs": false,
        "allowUnreachableCode": false,
        "allowUnusedLabels": false,
        "declaration": false,
        "declarationMap": false,
        "diagnostics": true,
        "removeComments": true,
        "module": "es6",
        "target": "es5",
        "strict": false
    },
    "include": [
        "src/**/*"
    ]
}
1
  • Try adding "moduleResolution": "node" to compilerOptions Commented Sep 14, 2018 at 17:00

1 Answer 1

1

With the "module": "es6" setting you have ES6 module generation. If your module is not node, TypeScript will default to Classic for module resolution. See: https://www.typescriptlang.org/docs/handbook/compiler-options.html

See: https://www.typescriptlang.org/docs/handbook/module-resolution.html -- which explains how Classic and Node module resolution work. You want "moduleResolution": "node" to import from node_modules the way you want.

You actually don't need module since target: ES5 will make module default to es6. You might want to revisit your setting for target.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.