我在编译项目时遇到问题。我一直在app - Copy/some.component.ts(6,32): error TS2307
。编译器工作,它编译打字稿,我可以在Windows IIS 7.5服务器上运行它,或者我可以在项目根目录中使用npm run lite
,它将运行应用程序。问题是我的package.json中的脚本我用来编译并继续监听文件的更改然后运行lite-server因为我收到npm run tsc
的错误而无效。另外,作为在Atom中构建项目时的注释,我也会遇到相同的错误。
提前致谢。
打印出命令行错误
> OPI-Training@1.0.0 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! OPI-Training@1.0.0 tsc: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the OPI-Training@1.0.0 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';
答案 0 :(得分:1)
我已经弄明白了这个问题。我备份了原来的app文件夹。因此," app - Copy"没有考虑任何事情。发生了什么npm run tsc
正在编译我复制的备份文件夹,这就是错误来自的地方。 Noob错误。