4

So I was writing in some comments in a new component I was writing, and then to my dismay, my laptop ran out of battery and turned off. I had my server running whilst this happened.

Normally this would be no big deal, I'll just turn it back on and boot up my server again, and continue developing. This time it decided to give me some errors:

cannot find name 'describe', and expect, and beforeEach, etc.

Note: this is essentially the same problem outlined in the bellow sources:

Now this being said, I am aware of the import {} from 'jasmine'; work-around. However, this is where my question stems from.

The above is just that, a "work-around". From all the time I've been working on my website, it has worked perfectly without ever needing the extra import on the spec files. I want to solve this issue, and make it work without the extra import. Thus far in my research I don't believe anyone has solved this issue.

Like in the above issues, I have node_modules/@types listed under "typeRoots" in my tsconfig.json.

I have @types/jasmine installed on the project.

The only thing I can think of right now is the fact that there are separate tsconfig files in the /src directory (/src/tsconfig.spec.json, /src/tsconfig.app.json), rather than the /tsconfig.json file.

In these files, there is another "types" section, and I see other "include" sections that I've seen some people reference.

Anyway, I'll include some config files for reference:

/src/tscongif.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

/src/tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts",
    "polyfills.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

/tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

let me know if you guys want any other files, and I'll add them.

Update

With the comments bellow, I have deleted the node_modules folder and re-installed the project. I have also verified npm's cache using the command npm cache verify. After this, my issue still persists.

Matt Strom
  • 516
  • 3
  • 19
  • So it worked before the laptop died? try deleting the `node_modules` folder and then running `npm install` again. What happens? – pizzaisdavid Dec 25 '18 at 06:36
  • No dice. Although for a second, VS Code thought it couldn't find @angular/core/testing, but some restarts seemed to fix that. I shouldn't need to delete cached node files should I? It said this when re-building: `Cached binary found at /home/matt/.npm/node-sass/4.10.0/linux-x64-64_binding.node` – Matt Strom Dec 25 '18 at 08:56
  • @MatthewStrom Basically, either your `node_modules` folder got corrupted or links were broken in VS Code. That's why, when you deleted `node_modules` folder and then ran `npm install`. It worked. – Saddam Pojee Dec 25 '18 at 13:48
  • 2
    @Saddam I think you misunderstand, deleting the `node_modules` folder and re-running `npm install` does not solve the issue. I have also ran `npm cache verify` to make sure the cache is clean and running fine. – Matt Strom Dec 26 '18 at 20:33

0 Answers0