"Cannot read property 'lastIndexOf' of undefined" when using import in typescript plugins file
See original GitHub issueCurrent behavior:
It seems as soon as I am trying to use an import { ... } from '...'
(import a separate .ts Typescript file from the project to be tested) in a plugins/index.ts
, cypress fails directly when executing cypress open
with the following error and stack trace:
Message: Cannot read property ‘lastIndexOf’ of undefined
Stack trace:
TypeError: Cannot read property 'lastIndexOf' of undefined
at Object.startsWith (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:2060:20)
at mangleScopedPackageName (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30540:16)
at mangleScopedPackageNameWithTrace (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30527:23)
at loadModuleFromImmediateNodeModulesDirectory (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30458:83)
at C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30435:39
at Object.forEachAncestorDirectory (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:6784:26)
at loadModuleFromNearestNodeModulesDirectoryWorker (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30429:19)
at loadModuleFromNearestNodeModulesDirectoryTypesScope (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30425:16)
at tryResolve (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30604:28)
at classicNameResolver (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:30580:24)
at Object.resolveModuleName (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\typescript\lib\typescript.js:29897:30)
at tsLookup (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\filing-cabinet\index.js:221:26)
at cabinet (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\filing-cabinet\index.js:75:18)
at Function.module.exports._getDependencies (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:104:20)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:149:37)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at traverse (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:171:24)
at Module.module.exports (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:35:19)
at Function.module.exports.toList (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\dependency-tree\index.js:72:17)
at Watchers.watchTree (C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\lib\watchers.js:60:30)
at C:\Users\me\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\lib\project.js:272:28
Desired behavior:
import {...} from '...'
can be used in plugins/index.ts
.
Test code to reproduce
- Add
import {...} from '../../myproject/any/file.ts' to the top of your
plugins/index.ts` Note: The import must not be used at all, it seems having it is enough to break displaying the tests list. - tsconfig in cypress directory is
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": [
"**/*.ts"
]
}
Versions
Cypress 4.7.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Documentation - Modules - TypeScript
Modules are declarative; the relationships between modules are specified in terms of imports and exports at the file level. Modules import one another...
Read more >Cannot read property 'indexOf' of undefined - Stack Overflow
The problem is that you're modifying the array while jQuery's $.each is looping over it, so by the time it gets to the...
Read more >Issue with 4.9.0 + webpack + typescript
app.js:28654 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>' at Object.<anonymous> (app.js:28654) at Object.push.
Read more >typeerror: cannot read properties of undefined ... - You.com
Reason : As there is no named export of ReactDOM from "react-dom", it is not imported and the reference will be undefined. So,...
Read more >rewiremock - npm
js file and require it - in this way, you can preconfigure rewiremock for all tests. for ts/es6/esm use import. // rewiremock.es6.js import...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jennifer-shehane I got this error on my machine with cypress 6.8.0 when I had this line in my code:
as soon as I removed it, cypress worked fine. I worked around this by replacing it with require for now, but require sucks, bucause they are not type safe in TS. Dynamic imports are.
Do you have any spec with a dynamic import in place here in the repository?
Also should I open a new bug for this dynamic import issue?