我按照此处提到的步骤将我的应用程序从 angular4 升级到 angular 5:https://update.angular.io/
我可以毫无问题地运行 ng-serve 、 ng build 等。
但是 ng 测试(npm 测试)失败并出现错误:
\src\test.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
我尝试了足够多的谷歌搜索并解决了这个问题,但它们似乎都没有用。
按照这里的建议, https://stackoverflow.com/a/48798373/2754029 我尝试在 angular-cli.json 和 tsconfig.json 中添加配置,但这不起作用。
任何人都可以在这里帮助我。如果您需要这方面的更多信息,请告诉我。
最佳答案
在我的例子中,那是因为 ng test
使用 tsconfig.spec.json
,而不是 tsconfig.json
。检查您的 tsconfig.spec.json
并且您的 test.ts
列在 files
部分中。
您可以在 angular.json
的以下部分查看/更改要使用的 tsconfig。
{
"projects": {
"YOUR_PROJECT": {
"architect": {
"test": {
"options": {
"tsConfig": "tsconfig.spec.json", // <---- See here
"karmaConfig": "src/YOUR_PROJECT/karma.conf.js"
参见 https://angular.io/guide/file-structure#default-app-project-files想要查询更多的信息。希望对您有所帮助。
关于angular - 从 angular4 升级到 angular 5 "test.ts is missing from the TypeScript compilation"后 npm 测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50851280/