0

I am using VScode with several react apps. For one of my projects, in the .js files I do not get the "Cannot find module 'typescript'. ts(2307)" alert on import something from './an/incorrect/path' lines, where I would expect that ts2307 alert.

However I do get that alert in .ts files that import from incorrect paths.

How do I get those alerts to appear as well in .js files?

I've checked that both of these settings are set to true in VScode settings.json. You want to change these two settings in VS Code's settings.json:

"typescript.validate.enable": true,
"javascript.validate.enable": true,

This is my tsconfig file.

{
    "compilerOptions": {
        "target": "ES5",
        "module": "commonjs",
        "lib": ["es2017", "dom"],
        "allowJs": true,
        "jsx": "react",
        "noImplicitAny": false,
        "noFallthroughCasesInSwitch": true,
        "moduleResolution": "node",
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "outDir": "lib"
    },
    "include": ["./**/*"]
}

1 Answer 1

0

I just found the answer, right after I considered that typescript checking might be entirely disabled for .js files. Then I found I had to add "checkJs": true to the compilerOptions in tsconfig.json.

ts2307 are now correctly shown when trying to import from incorrect file paths.

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.