Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karma throws errors when using custom source directory #2206

Closed
kucharzyk opened this issue Sep 18, 2016 · 10 comments
Closed

Karma throws errors when using custom source directory #2206

kucharzyk opened this issue Sep 18, 2016 · 10 comments
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix

Comments

@kucharzyk
Copy link

Karma throws errors when using custom source directory

  • Tests can't find jasmine methods when using custom source directory.
  • Tests run well with default source directory.

My cli version (running under Windows 10)

C:\>ng version
angular-cli: 1.0.0-beta.14
node: 6.6.0
os: win32 x64

Error log:

C:\demo>ng test
18 09 2016 22:44:34.517:WARN [karma]: No captured browser, open http://localhost:9876/

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
45:15 Critical dependency: the request of a dependency is an expression

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
57:15 Critical dependency: the request of a dependency is an expression

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:6:0
Cannot find name 'describe'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:7:2
Cannot find name 'beforeEach'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:15:2
Cannot find name 'it'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:18:4
Cannot find name 'expect'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:21:2
Cannot find name 'it'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:24:4
Cannot find name 'expect'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:27:2
Cannot find name 'it'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.spec.ts:31:4
Cannot find name 'expect'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.ts:5:12
Cannot find name 'require'.

ERROR in [default] C:\demo\aaa\bbb\ccc\app\app.component.ts:6:11
Cannot find name 'require'.
18 09 2016 22:44:34.538:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/
18 09 2016 22:44:34.538:INFO [launcher]: Launching browser Chrome with unlimited concurrency
18 09 2016 22:44:34.554:INFO [launcher]: Starting browser Chrome
18 09 2016 22:44:35.985:INFO [Chrome 53.0.2785 (Windows 10 0.0.0)]: Connected on socket /#yDvYLk6xqHJ7A9jPAAAA with id 65295348
Chrome 53.0.2785 (Windows 10 0.0.0): Executed 3 of 3 SUCCESS (0.211 secs / 0.192 secs)

How to reproduce:

C:\>ng new -sd aaa/bbb/ccc demo
installing ng2
  create README.md
  create aaa\bbb\ccc\app\app.component.css
  create aaa\bbb\ccc\app\app.component.html
  create aaa\bbb\ccc\app\app.component.spec.ts
  create aaa\bbb\ccc\app\app.component.ts
  create aaa\bbb\ccc\app\app.module.ts
  create aaa\bbb\ccc\app\index.ts
  create aaa\bbb\ccc\app\shared\index.ts
  create aaa\bbb\ccc\environments\environment.prod.ts
  create aaa\bbb\ccc\environments\environment.ts
  create aaa\bbb\ccc\favicon.ico
  create aaa\bbb\ccc\index.html
  create aaa\bbb\ccc\main.ts
  create aaa\bbb\ccc\polyfills.ts
  create aaa\bbb\ccc\styles.css
  create aaa\bbb\ccc\test.ts
  create aaa\bbb\ccc\tsconfig.json
  create aaa\bbb\ccc\typings.d.ts
  create angular-cli.json
  create e2e\app.e2e-spec.ts
  create e2e\app.po.ts
  create e2e\tsconfig.json
  create .gitignore
  create karma.conf.js
  create package.json
  create protractor.conf.js
  create tslint.json
Successfully initialized git.
Installing packages for tooling via npm.
Installed packages for tooling via npm.

C:\>cd demo

C:\demo>ng test

@andrewda
Copy link

I'm getting something similar when running the app:

ERROR in [default] /Users/.../my-project/src/app/app.component.ts:5:12 
Cannot find name 'require'.

ERROR in [default] /Users/.../my-project/src/app/app.component.ts:6:11 
Cannot find name 'require'.

Seems to be working despite the issues, though.

@kucharzyk
Copy link
Author

Yes. It seems to be working despite errors.

Maybe they come from tslint

@kvn
Copy link

kvn commented Sep 19, 2016

@andrewda: you can temporary add the following to src/typings.d.ts as a workaround:

declare var require: any;
declare var module: any;

@kucharzyk
Copy link
Author

Temporary solution that works for me is adding following declarations to typings.d.ts

declare var describe: any;
declare var expect: any;
declare var beforeEach: any;
declare var it: any;
declare var require: any;

@kucharzyk
Copy link
Author

Now I know what caused this errors.

tsconfig.json generated by angular-cli is incorrect.
"typeRoots" and "outDir" paths are wrong.

Just fix "typeRoots" path in your projects and everything will works without errors.

@eamell
Copy link

eamell commented Sep 19, 2016

Hi @kucharzyk,

What should the values of typeRoots and outDir be?

Thanks!

@eamell
Copy link

eamell commented Sep 19, 2016

Hi @kucharzyk,

The only issue I am seeing if the two warnings that you saw, I do not getting any errors. For reference the warnings are:

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
45:15 Critical dependency: the request of a dependency is an expression

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
57:15 Critical dependency: the request of a dependency is an expression

It works fine; I just as a rule try to get rid of errors and warnings as they often are results of bigger issues (even if that doesn't seem to be the case here).

Thanks!

@filipesilva filipesilva added type: bug/fix command: new P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Sep 22, 2016
@filipesilva filipesilva self-assigned this Sep 22, 2016
@filipesilva
Copy link
Contributor

Thanks for the investigation work @kucharzyk! #2206 (comment) does seem like a bug when we generate a project.

@thorsten
Copy link

thorsten commented Oct 4, 2016

Anyone working on this issue?

filipesilva added a commit to filipesilva/angular-cli that referenced this issue Oct 9, 2016
JJayet pushed a commit to JJayet/angular-cli that referenced this issue Oct 14, 2016
Brocco pushed a commit that referenced this issue Oct 19, 2016
texel pushed a commit to splice/angular-cli that referenced this issue Nov 3, 2016
heralight added a commit to heralight/fireloop-todo-example that referenced this issue Nov 11, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants