简体   繁体   English

使用typescript baseurl和路径会破坏React-Router

[英]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 我试图在tsconfig中设置baseUrls和路径,但每当我更改baseURL时我收到以下错误

 ./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. 我已经尝试在env config中设置node_path并将路径和baseurl移动到github线程中建议的单独的typescript文件,但是这不起作用。

So here is what I have as of now in the Tsconfig 所以这就是我现在在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 '.' 请注意将baseUrl更改回'.' fixes the issue but the custom paths will no longer work 修复了问题,但自定义路径将不再起作用

Typescript version is 3.3.1 打字稿版本为3.3.1

Alright a bit of a dolt here. 好吧这里有点磕磕绊绊。

Had a History.ts file in the "src" directory. "src"目录中有一个History.ts文件。 So changing the baseUrl to src was resulting in that location being checked first even in the third party libraries. 因此,将baseUrl更改为src会导致首先检查该位置,即使在第三方库中也是如此。 So needless to say that history object did not contain those definitions 所以,不用说历史记录对象并没有包含这些定义

Some folder/file reorganization fixed the issue 某些文件夹/文件重组修复了该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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