2016-10-20 3 views
2

Angular JavaScript (ES5) 프로젝트를 TypeScript 2.0으로 단계별로 마이그레이션하려고하는데 매우 고심하고 있습니다.
먼저 index.js를 index.ts로 변경하고 이전 typings.json 대신 recommended method of installing typings (npm install --save @types/node)을 사용했습니다.browserify + babelify + tsify로 TypeScript 입력이 누락되었습니다.

빌드 설정은 here을 제안 browserify 지금은 tsifybabelify을 도입하여 gulp를 사용합니다.

browserify

tsconfig.json

{ 
"files": [ 
    "assets/app/index.ts" 
], 
"compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false 
} 
} 

빌드가 실패하지만

//... 
.plugin(tsify) 
.transform(babelify, { 
     presets: ['es2015'], 
     extensions: ['.ts', '.js'] 
}) 
//... 
:

TypeScript error: .tmp/public/app/index.ts(4,15): Error TS2304: Cannot find name 'require'.

tsify가 채소를 복사하지 않는 것 같다 위의 오류를 일으키는 출력 dir에 타이핑을합니다.
문제를 해결하는 방법에 대한 제안이 있으십니까? 누군가가 동일로 실행

답변

1

경우 ... 드라이브 오류를 제거,하지만 난 아무 생각이 왜 :

편집
내 C의 루트 유형 @/ 폴더를 node_modules 복사 문제 :

tsconfig.json에 고정적으로 typesRoot 옵션을 추가했습니다.

"typeRoots" : ["./node_modules/@types"] 

"기본"으로 설정해야하지만 어떤 이유로 @ C : 드라이브 루트 아래 @types 폴더를 검색합니다. 타이프 문서에서

:

If typesRoots is specified, only packages under typeRoots will be included.

+0

사용하는 tsify의 버전은 무엇? – cartant

+0

' "tsify": "^ 2.0.2"' – lenny

+0

이 문제에 대해 [issue] (https://github.com/TypeStrong/tsify/issues)를 만들 수 있습니까? 그것은 마치 버그처럼 보입니다. 'typeRoots'를 지정할 필요는 없습니다. 문제에 더 많은 구성을 포함시킬 수 있습니까? '.tmp/public/... '과 같은 경로가 오류 메시지에서 어떻게 끝나야하는지 알 수 없습니다. – cartant

관련 문제