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

ng serve / ng test - import resolving difference ? #3533

Closed
vfedoriv opened this issue Dec 12, 2016 · 11 comments
Closed

ng serve / ng test - import resolving difference ? #3533

vfedoriv opened this issue Dec 12, 2016 · 11 comments
Labels
needs: repro steps We cannot reproduce the issue with the information given

Comments

@vfedoriv
Copy link

Please provide us with the following information:

OS?

Windows 10

Versions.

angular-cli: 1.0.0-beta.22-1
node: 7.2.0
os: win32 x64

Repro steps.

This import work with ng serve and not work with ng test:

import {environment} from 'environments/environment';

@Injectable()
export class OwnerService {

  private entity_url = environment.REST_API_URL + 'owners';

When start ng test :

ERROR in ./src/app/owners/owner.service.ts
Module not found: Error: Can't resolve 'environments/environment' in 'D:\eclipse\workspace\spring-petclinic-angular2\src\app\owners'
 @ ./src/app/owners/owner.service.ts 15:20-55
 @ ./src/app/app.component.ts
 @ ./src/app/app.component.spec.ts
 @ ./src \.spec\.ts
 @ ./src/test.ts

When I change import as

import {environment} from './../../environments/environment'

work ok for both (but it's lo-o-ong :) )

File environment.ts in src/environments/ directory.

Webpack config difference or something relate to ##2470 ?

@Juansasa
Copy link

I'm having the same problem, hopes it will be addressed soon

@Igonato
Copy link

Igonato commented Dec 14, 2016

Same Issue. Brakes app/* imports in tests

@hansl
Copy link
Contributor

hansl commented Dec 15, 2016

Do you have a baseUrl key in your tsconfig.json?

@vfedoriv
Copy link
Author

tsconfig as default generated, "baseUrl": ""

@hansl
Copy link
Contributor

hansl commented Dec 15, 2016

Could you provide a project that we can test against? I haven't seen that in beta 22-1 and/or Windows.

@hansl hansl added the needs: repro steps We cannot reproduce the issue with the information given label Dec 15, 2016
@Igonato
Copy link

Igonato commented Dec 16, 2016

@hansl I was on beta 22 updated to beta 22-1 and it went away

@vfedoriv
Copy link
Author

@hansl
Copy link
Contributor

hansl commented Dec 16, 2016

Thanks. We'll investigate and come back.

@hansl
Copy link
Contributor

hansl commented Dec 16, 2016

I found the problem with your

Using a local fix that I have to report errors more efficiently, this is what I see:

# ng serve --aot
** NG Live Development Server is running on http://localhost:4200. **
Hash: 1951a494f4f6edf25474
Time: 5870ms
chunk    {0} main.bundle.js, main.bundle.map (main) 59.9 kB {2} [initial] [rendered]
chunk    {1} styles.bundle.css, styles.bundle.map, styles.bundle.map (styles) 69 bytes {3} [initial] [rendered]
chunk    {2} vendor.bundle.js, vendor.bundle.map (vendor) 1.22 MB [initial] [rendered]
chunk    {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]

ERROR in Cannot determine the module for class PageNotFoundComponent in /Users/hansl/Sources/_Temp/test1/src/app/common/page-not-found/page-not-found.component.ts!

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app/app.module.ngfactory' in '/Users/hansl/Sources/_Temp/test1/src'
 @ ./src/main.ts 4:0-64
 @ multi main

ERROR in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
Module not found: TypeError: Cannot convert undefined or null to object
 @ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js 69:15-36 85:15-102
 @ ./~/@angular/core/src/linker.js
 @ ./~/@angular/core/src/core.js
 @ ./~/@angular/core/index.js
 @ ./src/main.ts
 @ multi main
webpack: bundle is now VALID.

The error is "Cannot determine the module for class PageNotFoundComponent". Every components built need to be declared in an NgModule, so this is an error.

Two things you can do to fix:

  1. add the component to a module's declaration (which seems like what you'd like to do)
  2. change the tsconfig to only compile the main.ts (adding "files": ["main"]).

Point 2 we can actually improve on by having main.ts in our tsconfig by default when creating new apps, so we'll do that. In the meantime you have fixes for this problem and I'll close this issue as fixed.

Cheers!

@hansl hansl closed this as completed Dec 16, 2016
@vfedoriv
Copy link
Author

Well, i generate clean project w/o other logic and just add one import.
Same error with 'ng test'
Try this: https://github.com/vfedoriv/test3.git

@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
needs: repro steps We cannot reproduce the issue with the information given
Projects
None yet
Development

No branches or pull requests

4 participants