nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.62k stars 2.36k forks source link

Unable to run karma tests from Webstorm after adding nrwl workspace #4386

Closed burgerwagon closed 3 years ago

burgerwagon commented 3 years ago

Current Behavior

When running a karma test from within Webstorm it fails with the error

ERROR [config]: Error in config file!
  Error: Cannot find module 'D:\tmp\js-karma-path-issue\"C:\Program Files (x86)\JetBrains\WebStorm 2020.1\plugins\js-karma\js_reporter\karma-intellij\lib\intellij.conf.js"'

Debugging further i can see that in .\node_modules\@angular-devkit\build-angular\src\karma\index.js:91 the following line sets up the path karmaOptions.configFile = path_1.resolve(context.workspaceRoot, options.karmaConfig);

The path in the options.karmaConfig is getting passed in wrapped in quotes. This is causing path.resolve to not recognise this as an absolute url and just appends it to the workspaceRoot. The resulting url is the one from the error above. This does not happen before nx is added to the project.

This error seems to be caused by the decorating of ng-cli. If i remove node_modules and remove the call to node ./decorate-angular-cli.js from the postinstall in package.json and then do another npm install the problem does not occur

Expected Behavior

I expect the tests to execute successfully from within webstorm

Steps to Reproduce

I'm using Webstorm 2020.1 and have @angular/cli@11.0.5 installed globally

I can reproduce the error with these minimal steps

Failure Logs

"C:\Program Files\nodejs\node.exe" D:\tmp\js-karma-path-issue\node_modules\@angular\cli\bin\ng test js-karma-path-issue --karma-config "C:\Program Files (x86)\JetBrains\WebStorm 2020.1\plugins\js-karma\js_reporter\karma-intellij\lib\intellij.conf.js" --source-map

> nx run js-karma-path-issue:test --karma-config="C:\Program Files (x86)\JetBrains\WebStorm 2020.1\plugins\js-karma\js_reporter\karma-intellij\lib\intellij.conf.js" --karmaConfig="C:\Program Files (x86)\JetBrains\WebStorm 2020.1\plugins\js-karma\js_reporter\karma-intellij\lib\intellij.conf.js" --source-map --sourceMap 
23 12 2020 12:12:57.666:ERROR [config]: Error in config file!
  Error: Cannot find module 'D:\tmp\js-karma-path-issue\"C:\Program Files (x86)\JetBrains\WebStorm 2020.1\plugins\js-karma\js_reporter\karma-intellij\lib\intellij.conf.js"'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at Module.require (D:\tmp\js-karma-path-issue\packages\tao\src\compat\compat.ts:9:36)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.parseConfig (D:\tmp\js-karma-path-issue\node_modules\karma\lib\config.js:358:22)
    at new Server (D:\tmp\js-karma-path-issue\node_modules\karma\lib\server.js:65:24)
    at Observable.rxjs_1.Observable.subscriber [as _subscribe] (D:\tmp\js-karma-path-issue\node_modules\@angular-devkit\build-angular\src\karma\index.js:105:29)
    at Observable._trySubscribe (D:\tmp\js-karma-path-issue\node_modules\rxjs\src\internal\Observable.ts:238:19)
    at Observable.subscribe (D:\tmp\js-karma-path-issue\node_modules\rxjs\src\internal\Observable.ts:219:14)
    at Object.innerSubscribe (D:\tmp\js-karma-path-issue\node_modules\rxjs\src\internal\innerSubscribe.ts:111:19)
    at SwitchMapSubscriber._innerSub (D:\tmp\js-karma-path-issue\node_modules\rxjs\src\internal\operators\switchMap.ts:137:30)
    at SwitchMapSubscriber._next (D:\tmp\js-karma-path-issue\node_modules\rxjs\src\internal\operators\switchMap.ts:126:10)
    at SwitchMapSubscriber.Subscriber.next (D:\tmp\js-karma-path-issue\node_modules\rxjs\src\internal\Subscriber.ts:99:12)
    at D:\tmp\js-karma-path-issue\node_modules\rxjs\src\internal\util\subscribeToPromise.ts:8:20
    at process._tickCallback (internal/process/next_tick.js:68:7)

Process finished with exit code 1

Environment

Node : 10.16.0 OS : win32 x64 npm : 6.9.0

nx : Not Found @nrwl/angular : 11.0.18 @nrwl/cli : 11.0.18 @nrwl/cypress : 11.0.18 @nrwl/devkit : 11.0.18 @nrwl/eslint-plugin-nx : Not Found @nrwl/express : Not Found @nrwl/jest : 11.0.18 @nrwl/linter : 11.0.18 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 11.0.18 @nrwl/web : Not Found @nrwl/workspace : 11.0.18 typescript : 4.0.5

brandonroberts commented 3 years ago

Please verify with the latest release of Nx 11 and reopen if necessary. I wonder if this is Windows-specific as I was not able to reproduce on OSX and WebStorm 2020.1

baltie commented 3 years ago

In case the original author doesn't respond, this is still an issue with latest release of Nx 11, I am unable to run the tests in WebStorm. It seems to be Windows specific as my colleague that uses a Mac doesn't have this problem.

brandonroberts commented 3 years ago

Thanks @baltie

burgerwagon commented 3 years ago

Thanks @baltie. Yes we are on Windows and is still an issue

danderwald commented 3 years ago

I have the same issue on a Mac:

after upgrading from nx10 to nx11

The error:

  Error: Cannot find module '/Users/xxxx/Development/something/"/Users/xxxx/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/203.7148.54/WebStorm.app/Contents/plugins/js-karma/js_reporter/karma-intellij/lib/intellij.conf.js"'
github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.