2017-06-03 121 views
-1

src/shared/components/A.tsx,做import B from 'components/B'src/shared/components/B.tsx打字稿使用ES6模塊

打字稿給我一個錯誤有一個文件「找不到模塊 」錯誤 cannot find module 'components/B'

這是我tsconfig.json文件,該文件是在根目錄:

{ 
    "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 
     ] 
    } 
} 

我從https://www.typescriptlang.org/docs/handbook/tsconfig-json.html理解是,它會試圖找到./components/B第一,它不不存在,然後進入<baseUrl>/src/shared/components/B,這是文件存在的位置,所以我不知道爲什麼我仍然看到一個錯誤。

+0

出於好奇 - 如果您將'.jsx'文件重命名爲'.js'文件,這是否工作?如果你用'.jsx'作爲後綴顯式導入,那麼它是否解決了它? –

+0

它工作之前,我移植到打字稿,如果我改變文件擴展名打字稿不會拋出錯誤的文件。但是,模塊B在代碼中存在錯誤,導致它無法編譯......打字稿是否嘗試編譯導入到文件中的模塊? – PDN

回答

0

嗯,這是愚蠢的,paths/baseUrl屬於compilerOptions