tsc가 로컬파일에 대해 TS2307: Cannot find module을 슬로우합니다.
TypeScript를 사용한 간단한 예시 프로젝트가 있습니다.https://github.com/unindented/ts-webpack-example
.tsc -p . 함께)tsc.8..
app/index.ts(1,21): error TS2307: Cannot find module 'components/counter'.
components/button/index.ts(2,22): error TS2307: Cannot find module 'shared/backbone_base_view'.
components/button/index.ts(3,25): error TS2307: Cannot find module 'shared/backbone_with_default_render'.
components/counter/index.ts(2,22): error TS2307: Cannot find module 'shared/backbone_base_view'.
components/counter/index.ts(3,25): error TS2307: Cannot find module 'shared/backbone_with_default_render'.
components/counter/index.ts(4,27): error TS2307: Cannot find module 'shared/backbone_with_subviews'.
components/counter/index.ts(5,20): error TS2307: Cannot find module 'components/button'.
다음과 같은 로컬 파일의 모든 Import에 대해 불만을 제기합니다.
import Counter from 'components/counter';
상대 경로로 변경하면 작동하지만 파일을 이동할 때 생활이 더 어려워지기 때문에 원하지 않습니다.
import Counter from '../components/counter';
vscodecodebase는 상대 경로를 사용하지 않지만 모든 것이 정상적으로 동작하기 때문에 프로젝트에 뭔가 부족한 것이 있을 수 있습니다.https://github.com/Microsoft/vscode/blob/0e81224179fbb8f6fda18ca7362d8500a263cfef/src/vs/languages/typescript/common/typescript.ts#L7-L14
GitHub 하실 수 만약 GitHub repo, repo, GitHub repo, GitHub repo, GitHub repo, GitHub repo, GitHub repo, GitHub repo가 있습니다.tsconfig.json"이것들"은 다음과 같습니다.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"noImplicitAny": false,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "dist"
},
"exclude": [
"dist",
"node_modules"
]
}
것은 funny밌 through through through through through through through through funny funny funny funny 。webpack를 사용합니다.ts-loader정상적으로 동작하고 있기 때문에, 설정상의 문제라고 생각됩니다.
@vladima는 GitHub에서 이 문제에 답했습니다.
됩니다.moduleResolution 옵션은 moduleResolution으로, moduleResolution은 moduleResolution으로 할 수 .
node★★★★★★★★★★★★★★★★★」classic(자세한 내용은 이쪽에서 확인할 수 있습니다).이 설정을 생략하면 컴파일러는 이 설정을node이 「」인commonjs★★★★★★★★★★★★★★★★★」classic않으면 -그렇지 않으면. -그렇지 않으면., 만약 , 당신은 그것을 할 수 있다.classic과 함께 사용commonjs- - 을 사용하여 명시적으로.{ "compilerOptions": { "moduleResolution": "node" } }
.includemanager.manager로 하다
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"sourceMap": false,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src/**/*.ts", "tests/**/*.ts"],
"exclude": ["node_modules", ".vscode"]
}
문제는 다른 환경에서 건물을 짓는 것이었습니다.제 OSX 빌드에서는 문제가 없었습니다.그러나 Linux 환경을 기반으로 구축하려고 하면 실패하고 있었습니다.그 배경에는, operating system의 대문자와 소문자의 구별이 있었습니다.이 문제를 겪고 있는 사람은 수입품에 대소문자를 구분해 주세요.
파일 구조:
/X/Y.ts
Import:
import Y from "./x/Y.ts";
그래서 저는 "x"를 대문자화하는 것을 수정했습니다.
import Y from "./X/Y.ts";
VS2019의 프로젝트 속성 페이지인 TypeScript Build 탭에는 "Module System"에 대한 설정(드롭다운)이 있습니다.그것을 「ES2015」에서 「CommonJS」로 변경했을 때, VS2019 IDE는 「Axios도 redux-thunk도 찾을 수 없다」(TS2307)고 불평하지 않게 되었습니다.
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "src",
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": [
"es6",
"dom",
"es2015.promise"
],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"outDir": "build/dist",
"rootDir": "src",
"sourceMap": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es5",
"skipLibCheck": true,
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"exclude": [
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts",
"node_modules",
"obj",
"**/*.spec.ts"
],
"include": [
"src",
"src/**/*.ts",
"@types/**/*.d.ts",
"node_modules/axios",
"node_modules/redux-thunk"
]
}
vscoode 코드베이스는 상대 경로를 사용하지 않지만 모든 것이 정상적으로 작동합니다.
모듈 로더에 따라 다릅니다.「 」를 사용하고 systemjsbaseurl 버전을 으로 함).VSCode는 이전 버전의 requirej를 기반으로 자체 사용자 지정 모듈 로더를 사용합니다.
권고
합니다.commonjs서포트하고 있습니다.파일을 이동하면 타이프스크립트 컴파일 시간 에러(좋은 점)가 발생하므로 대부분의 순수 js 프로젝트보다 더 나은 결과를 얻을 수 있습니다(npm).
저도 이 오류가 발생했어요.VSCode GitHub 의h 。 from from from from from from from from from from from from from from from from from from 의 파일 이름을 바꿨다.page.ts로로 합니다.Page.ts이치노내 지역 시스템은 모든 것이 잘 되었다. GitHub Actions에서 수 Page를 찾을 수 없습니다.
잠시 후 리모트 브랜치에서는 파일명이 변경되지 않은 것을 알게 되었습니다(단, 그 이상의 변경은 있었습니다).GitHub 웹 UI를 통해 다시 이름을 변경했고 빌드도 성공적으로 실행되었습니다.
따라서 TS2307에서 CI/CD 빌드가 실패했을 경우 리모트브런치에서 이를 확인합니다.
" " " "baseUrl": "."는 절대 절절경경((((((((((((((((((((:"src/components/button"를 참조해 주세요.
and고 and and를 추가한다."paths"특정 폴더부터 시작할 수 있습니다.그래서, 당신의 안에서tsconfig.json할 수 : "파일", "파일":
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["src/components/*"]
}
}
}
또한 구성을 추가한 후 VS 코드를 다시 시작해야 제대로 작동할 수 있습니다.
는 그 은 올바른 것을 이었다.baseUrl ★★★★★★★★★★★★★★★★★」pathscompilerOptionstsconfig.json 파일:-
{
...
"compilerOptions": {
...
"moduleResolution": "node",
...
"baseUrl": ".", // Here... try with correct values and the issue should get fixed
"paths": {
"*": ["src/*"] // Here... try with correct values and the issue should get fixed
}
}
...
}
웹스톰을 사용하는 경우 Ctrl+Alt+S를 누르고 설정창을 띄웁니다언어 및 프레임워크 >TypeScript 를 입력하고, 「use tsconfig.json」옵션을 유효하게 합니다.
다음 업데이트에서 이 오류가 발생했습니다.npm run watch ★★★★★★★★★★★★★★★★★」npm run hot 때도, .npm run dev ★★★★★★★★★★★★★★★★★」npm run prod.
은 in과 합의 이 되었습니다.webpack ★★★★★★★★★★★★★★★★★」ts-loader 「」를 참조해 주세요.
클래스 파일의 이름이 올바르게 지정되지 않은 경우 오류가 발생할 수 있습니다.는 업업 named named named named named named named named named named named라는 이름의 .EmployeeEmployee.ts
을 '다'로 ..ts ★★★★★★★★★★★★★★★★★」.d.ts
면책사항:OP가 요구한 (!)가 아니라 이 질문의 다른 방문자에게 도움이 될 수 있습니다.
상대 경로로 경로를 변경합니다.
부터
import x from 'src/foobar/x';
로.
import x from '../foobar/x';
웹스톰을 , 는 웹스톰을했습니다.include입니다.tsconfig.js다음과 같이 합니다.
"include": [
"src/**/*.tsx"
]
그리고 비올라도, 난 괜찮아.
"baseUrl" : " ." 를 추가하는 것이 도움이 되었습니다.
tsconfig.json에서 compilerOptions{} 뒤에 다음 행을 포함합니다.
"node" : ["node_displays"" 。
이것으로 오류가 해결되었습니다.
웹스톰에서 현재 파일 대신 새 파일을 만들고, 이전 파일의 내용을 새 파일로 복사하고, 이전 파일을 제거한 다음 새 파일의 이름을 이전 파일로 변경할 수 있습니다.이제 당신은 Import 파일을 할 수 있습니다. 이것은 나에게 효과가 있습니다.
언급URL : https://stackoverflow.com/questions/37548734/tsc-throws-ts2307-cannot-find-module-for-a-local-file
'programing' 카테고리의 다른 글
| Wordpress 플러그인 개발을 학습하기 위한 최고의 튜토리얼? (0) | 2023.03.27 |
|---|---|
| Jest에서 조롱된 서비스로 인해 "The module factory of jest.mock() is not allowed to reference any of scope variables" 오류가 발생합니다. (0) | 2023.03.27 |
| WordPress 함수에서 여러 Google 글꼴을 큐에 넣을 수 없는 이유는 무엇입니까? (0) | 2023.03.27 |
| 무시하기 위한 Jquery Ajax 오류 처리 중단됨 (0) | 2023.03.27 |
| Oracle 테이블/컬럼/인덱스 이름이 30자로 제한되는 이유는 무엇입니까? (0) | 2023.03.27 |