'Cypress inserting "node_module" in search path
I recently installed Cypress for running tests in my angular application, but whenever I try to run a test that has a import, I face this error:
Error: Webpack Compilation Error
./src/main/webapp/app/shared/util/mesh-math.util.ts
Module not found: Error: Can't resolve 'app/shared/model/enumerations/method-inrush.model' in 'C:\Projetos Headot\mesh\src\main\webapp\app\shared\util'
resolve 'app/shared/model/enumerations/method-inrush.model' in 'C:\Projetos Headot\mesh\src\main\webapp\app\shared\util'
Parsed request is a module
using description file: C:\Projetos Headot\mesh\package.json (relative path: ./src/main/webapp/app/shared/util)
Field 'browser' doesn't contain a valid alias configuration
Looked for and couldn't find the file at the following paths:
[C:\Projetos Headot\mesh\src\main\webapp\app\shared\util\node_modules]
[C:\Projetos Headot\mesh\src\main\webapp\app\shared\node_modules]
[C:\Projetos Headot\mesh\src\main\webapp\app\node_modules]
[C:\Projetos Headot\mesh\src\main\webapp\node_modules]
[C:\Projetos Headot\mesh\src\main\node_modules]
[C:\Projetos Headot\mesh\src\node_modules]
[C:\Projetos Headot\node_modules]
[C:\node_modules]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model.js]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model.json]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model.jsx]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model.mjs]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model.coffee]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model.ts]
[C:\Projetos Headot\mesh\node_modules\app\shared\model\enumerations\method-inrush.model.tsx]
@ ./src/main/webapp/app/shared/util/mesh-math.util.ts 27:28-88
@ ./src/test/javascript/spec/app/shared/util/mesh-math.util.spec.ts
at Watching.handle [as handler] (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\packages\server\node_modules\@cypress\webpack-preprocessor\dist\index.js:180:23)
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Watching.js:99:9
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)
at Watching._done (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Watching.js:98:28)
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Watching.js:73:19
at Compiler.emitRecords (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:499:39)
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Watching.js:54:20
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:485:14
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:482:27
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\neo-async\async.js:2818:7
at done (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\neo-async\async.js:3522:9)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:464:33
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\graceful-fs\graceful-fs.js:143:16
at C:\Users\Pichau\AppData\Local\Cypress\Cache\9.5.2\Cypress\resources\app\node_modules\graceful-fs\graceful-fs.js:61:14
at FSReqCallback.oncomplete (node:fs:188:23)
Here is my tsconfig.json file:
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.e2e.json"
}
],
"compilerOptions": {
"strictPropertyInitialization": false,
"strictNullChecks": false
}
}
And my tsconfig.base.json file, which holds the "paths":
{
"compilerOptions": {
"target": "es6",
"module": "esnext",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"outDir": "build/resources/main/static/app",
"lib": ["es7", "dom"],
"baseUrl": "./",
"paths": {
"app/*": ["src/main/webapp/app/*"]
},
"importHelpers": true,
"downlevelIteration": true,
"declaration": false,
"forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": false,
"strictNullChecks": false
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"fullTemplateTypeCheck": true,
"strictTemplates": true,
"preserveWhitespaces": true
}
}
cypress.json also has minimal configuration, only holding the tests location:
{
"integrationFolder": "src/test/javascript/spec/app"
}
It seems that the problem is that, somehow, "node_modules" has been added to the path when looking for the files. I have no idea why it's doing that, though, nor do I know how to stop it.
In case it helps, these are the imports inside the mesh-math file:
import { MethodInrush } from 'app/shared/model/enumerations/method-inrush.model';
import { Transformer } from 'app/shared/model/transformer.model';
import { Impedancia } from 'app/shared/model/impedancia.model';
import Complex from 'complex-js';
import { DealershipSetting } from 'app/shared/model/dealership-setting.model';
And this is the simple test I'm trying to run:
import {MeshMathUtil} from "../../../../../../main/webapp/app/shared/util/mesh-math.util";
describe('Mesh Math Util', () => {
it('should fail', () => {
expect(MeshMathUtil.isZero(3)).toBeFalsy();
})
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
