2016-08-19 68 views
2

定義所以我得到這個錯誤:app.component.ts沒有項目由tsconfig.json

File C:/wamp/www/angular2_demo/GiphySearch/src/app/app.component.tsis not in project defined by C:/wamp/www/angular2_demo/GiphySearch/e2e/tsconfig.json

我的文件夾結構

/ 
/e2e/tsconfig.json 
/src 
(others) 

tsconfig.js有這個內容

{ 
    "compileOnSave": false, 
    "compilerOptions": { 
    "declaration": false, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "mapRoot": "", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "noEmitOnError": true, 
    "noImplicitAny": false, 
    "rootDir": ".", 
    "sourceMap": true, 
    "sourceRoot": "/", 
    "target": "es5" 
    } 
} 

我試圖更改rootDirsourceRoot,將其定義爲../../src/src但沒有任何工作。應該如何正確配置?

+0

你試過'。/ src'嗎?我的angular-cli生成的tsconfig位於/ src裏面,只包含''mapRoot「:」./「' – j2L4e

+0

仍然不能正常工作 – Pentium10

回答

1

上tsconfig.json documentation定義:

The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project.

你有你的tsconfig.json在你的E2E目錄,而不是在src目錄下,它應該根據上面的鏈接。

我還注意到,你有"sourceRoot": "/",會改變它爲./的幫助?

+0

不知道爲什麼e2e文件夾中生成的angular-cli。我什至不明白那個文件夾是關於什麼的。 – Pentium10

1

我有同樣的問題,我替換了"outDir": ".""outDir": ""

這是我目前tsconfig.json

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
     "target": "es5", 
     "module": "commonjs", 
     "outDir": "", 
     "rootDir": "./_src/", 
     "emitDecoratorMetadata": true, 
     "experimentalDecorators": true, 
     "removeComments": true, 
     "moduleResolution": "node", 
     "noImplicitAny": false 
    }, 
    "include" : [ 
     "_src/**/*" 
    ], 
    "exclude": [ 
     "node_modules" 
    ] 
} 
+0

謝謝我有類似的問題,我剛剛添加了排除和compileOnSave,它開始正常工作! –

0

檢查了這一點!這對我有用。

{ 
    "compilerOptions": { 
     "target": "es5", 
     "module": "commonjs", 
     "moduleResolution": "node", 
     "sourceMap": true, 
     "emitDecoratorMetadata": true, 
     "experimentalDecorators": true, 
     "lib": [ "es2015", "dom" ], 
     "noImplicitAny": true, 
     "suppressImplicitAnyIndexErrors": true 
    }, 
    "files": [ 
     "../src/app/app.component.ts", 
     "../src/app/app.component.spec.ts", 
     "../src/app/app.module.ts" 
    ] 
} 
+0

是的,它的工作可以解釋你在做什麼。 – nilesh

2

NetBeans項目可能是建立索引整個NG2-CLI目錄作爲一個單一來源的根,因爲有其下多個tsconfig.json文件(一個在SRC打破這個插件/和一個在e2e /中)。

在項目屬性中的「Sources」類別下,將「Site Root Folder」和「Source Folder」設置爲src。 (如果你想編輯也可以將「Selenium Tests Folder」設置爲e2e)。

+0

Thx!這是涉及多個tsconfig文件的項目的正確答案。然後,配置文件似乎無法再通過「項目」選項卡訪問,因此必須通過「文件」選項卡(Windows>文件)進行訪問。 – Bob