0

I have a file in src/shared/components/A.tsx that does import B from 'components/B' (src/shared/components/B.tsx)

Typescript gives me an error cannot find module 'components/B'

This is my tsconfig.json file which is in the root directory:

{
  "compilerOptions": {
      "outDir": "./dist/",
      "sourceMap": true,
      "module": "es6",
      "target": "es6",
      "jsx": "react",
      "allowJs": true,
      "moduleResolution": "node"
  },
  "include": [
      "src/**/*"
  ],
  "exclude": [
      "node_modules"
  ],
  "baseUrl": ".",
  "paths": {
      "*": [
        "*",
        "src/shared/*" //this doesn't seem to work
      ]
  }
}

My understanding from https://www.typescriptlang.org/docs/handbook/tsconfig-json.html is that it will try to find ./components/B first, which does not exist, then go into <baseUrl>/src/shared/components/B, which is where the file exists, so I'm not sure why I'm still seeing an error.

2
  • Out of curiosity - if you rename the .jsx file to a .js file, does that work? If you explicitly import with .jsx as a suffix, does that fix it? Commented Jun 3, 2017 at 23:49
  • It worked before I ported to typescript and if I change the file extension Typescript won't throw errors in the file. However, module B has errors in the code which would prevent it from compiling... Does typescript attempt to compile modules that are imported into a file? Commented Jun 4, 2017 at 0:17

1 Answer 1

1

Well this was silly, paths / baseUrl belong inside compilerOptions.

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.