简体   繁体   中英

Using typescript baseurl and paths breaks React-Router

I am trying to set baseUrls and paths in the tsconfig, however whenever I change the baseURL I recieve the following error

 ./node_modules/react-router/es/StaticRouter.js 120:40-54 'history' does not contain an export named 'createLocation'. 

I have tried setting the node_path in env config and moving the path and baseurl to a seperate typescript file as was suggested in a github thread, however this did not work.

So here is what I have as of now in the Tsconfig

{
  "compilerOptions": {
    "baseUrl": "src",
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "paths": {
      "sagas/*": ["sagas/*"],
      "src/*": ["./*"],
      "*": [ "node_modules/@types/*", "*"]
    }
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "build",
    "lib",
    "tests",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "__mocks__",
    "__test__",
    "src/setupTests.ts"
  ]
}

Please note changing baseUrl back to '.' fixes the issue but the custom paths will no longer work

Typescript version is 3.3.1

Alright a bit of a dolt here.

Had a History.ts file in the "src" directory. So changing the baseUrl to src was resulting in that location being checked first even in the third party libraries. So needless to say that history object did not contain those definitions

Some folder/file reorganization fixed the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM