0
我在編譯我的項目時遇到問題。我一直在收到app - Copy/some.component.ts(6,32): error TS2307
。編譯器工作,它編譯打字稿,我可以在Windows IIS 7.5服務器上運行它,或者我可以在項目根目錄中使用npm run lite
,它將運行該應用程序。問題是我的package.json中的腳本用於編譯和保持監聽文件的更改,然後運行lite服務器不起作用,因爲我收到的錯誤npm run tsc
。在Atom中構建項目時,我也會遇到同樣的錯誤。在打字稿編譯中出現TS2307錯誤。
在此先感謝。
命令行錯誤打印出來
> [email protected] tsc C:\inetpub\wwwroot\OPI-Training-Angular2
> tsc
app - Copy/app.component.ts(6,32): error TS2307: Cannot find module './logon/logon.component'.
app - Copy/app.component.ts(7,35): error TS2307: Cannot find module './employee/employee.component'.
app - Copy/components/logon/logon.component.ts(3,29): error TS2307: Cannot find module '../user.service'.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run
" "tsc"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] tsc: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] tsc script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the OPI-Training package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs OPI-Training
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls OPI-Training
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\inetpub\wwwroot\OPI-Training-Angular2\npm-debug.log
PS C:\inetpub\wwwroot\OPI-Training-Angular2>
這裏是我的文件夾結構的屏幕截圖。
這裏是我的tsconfig.ts
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
這裏是我的package.json文件中的腳本
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
終於在各自的文件進口
app.components.ts 個
import { UserService } from '../../services/users/user.service';
import { LogonComponent } from '../logon/logon.component';
import { EmployeeComponent } from '../employee/employee.component';
logon.components.ts
import { UserService } from '../../../app/services/users/user.service';
那麼它無法找到您的導入,您是否從另一個ts文件複製並粘貼它們?這些路線不是指向任何東西,或者他們不能找到 – jhhoff02
這是它找到它們的東西。如果我更改其中一個導入獲取相同的三個錯誤,但也是這樣。 'app/components/app/app.component.ts(6,32):錯誤TS2307:找不到模塊'./logon/logon.component'.',如果我改回它,這個錯誤消失。 –