-1

I'm trying to run testing on my project, when running e2e (either by "ng e2e" or running the protractor code from my PhpStorm testing tool).

The error I'm getting in "ng e2e" is

DevTools listening on ws://127.0.0.1:60945/devtools/browser/79a66426-83f8-4059-888c-4e6a27bd09b5
[06:22:32] E/launcher - Error: Error: Cannot find module './env'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\www\blankblankproject\e2e\src\app.e2e-spec.ts:3:1)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Module.m._compile (C:\www\blankblankproject\node_modules\ts-node\src\index.ts:400:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\www\blankblankproject\node_modules\ts-node\src\index.ts:403:12)
    at Module.load (internal/modules/cjs/loader.js:600:32)
[06:22:32] E/launcher - Process exited with error code 100
An unexpected error occurred: undefined

and if I run it in PhpStorm it's

"C:\Program Files\nodejs\node.exe" C:\www\blankblankproject\node_modules\protractor\bin\protractor "C:\Program Files\JetBrains\PhpStorm 2019.1\plugins\JavaScriptLanguage\helpers\protractor-intellij\lib\protractor-intellij-config.js" --intellijOriginalConfigFile=C:\www\blankblankproject\e2e\protractor.conf.js --disableChecks
[06:39:27] I/launcher - Running 1 instances of WebDriver
[06:39:27] I/direct - Using ChromeDriver directly...
[06:39:31] E/launcher - Error: Error: Cannot find module './env'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\www\blankblankproject\e2e\src\app.e2e-spec.ts:3:1)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Module.m._compile (C:\www\blankblankproject\node_modules\ts-node\src\index.ts:400:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\www\blankblankproject\node_modules\ts-node\src\index.ts:403:12)
    at Module.load (internal/modules/cjs/loader.js:600:32)
[06:39:31] E/launcher - Process exited with error code 100

Process finished with exit code 4

Thank you for any help

user1037607
  • 133
  • 2
  • 12
  • What's your environment source path? – andreybleme Jun 21 '19 at 12:51
  • I'm sorry, I'm not quite sure how to locate that. Where can I find it? – user1037607 Jun 21 '19 at 13:18
  • looks as if you have `require("./env")` in one of your files (`C:\www\blankblankproject\e2e\src\app.e2e-spec.ts`?) and this module can't be resolved. If you need to read `.env` files, try using [dotenv](https://www.npmjs.com/package/dotenv) module - it allows loading environment from `.env` files using `require('dotenv').config({path: 'yourfile.env'}` – lena Jun 21 '19 at 13:18
  • Thank you everyone, it was a local definitions issue. – user1037607 Jun 24 '19 at 11:41

3 Answers3

0

Most likely because of this: Error: Error: Cannot find module './env'
Somewhere you are targeting another file without the correct path, perhaps here internal/modules/cjs/helpers.js:22:18 ?

Joaquin Casco
  • 704
  • 5
  • 14
0

Learn to use stack traces.

The latests events are on top, so start reading it from top to bottom.

First you see your error Error: Cannot find module './env' Lets assume you have no idea what it means

Next line is useless, as well as all others that don't belong to your project. So go down until you get at Object.<anonymous> (C:\www\blankblankproject\e2e\src\app.e2e-spec.ts:3:1)

This line says in your app.e2e-spec.ts file at line 3 your error occurred. So go there and explore what you have on that line. Most likely you're requiring './env' module. This means you are expecting to have either a folder or a file called env in the same directory where your spec is, but it's not there.

Figure out if you need this file in your tests. If so, create it, if not, remove that line from the spec

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
0

I am guess your folder structure and answering this

In your test file e2e-spec.ts at line number 3 you need to make it require/import a module statement with two dots like ../env instead of one dot.

Ajitesh
  • 16
  • 2