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

Services do not work in production build #808

Closed
unnijeevan opened this issue May 18, 2016 · 7 comments
Closed

Services do not work in production build #808

unnijeevan opened this issue May 18, 2016 · 7 comments

Comments

@unnijeevan
Copy link

  1. OS? Windows 10
  2. Versions. 1.0.0-beta.1

3.Created a sample app using angular cli and created a service under shared folder.
Run ng build -prod
Run ng serve -prod
Get error

"Error loading http://localhost:4200/app/shared/index.js as "./app/shared" from http://localhost:4200/main.js ; Zone: ; Task: Promise.then ; Value: Error: Error: XHR error (404 Not Found) loading http://localhost:4200/app/shared/index.js(…)"

  1. Not happening in dev build/

test.zip

@filipesilva
Copy link
Contributor

Heya @unnijeevan, I tried this on 1.0.0-beta.4 and it seems to be fixed. Can I ask you to update your version and try again?

My commands were these:

ng new testproj
cd testproj
ng generate service my-test-service
ng serve -prod

@unnijeevan
Copy link
Author

Hi filip

Thank you very much for the reply,it works now but it seems prod build doesn't bundle things anymore...Previously it used to be just 4 or 5 miles bundled.Not sure how is it different from dev build now

@filipesilva
Copy link
Contributor

filipesilva commented May 19, 2016

The app itself is bundled, even though all vendor files are being copied over to dist/ - this seems to be a bug, which I'll look at in #829.

Check your main.ts - it should have all code for vendor files bundled there. app/index.js should also have a bundle of all your app code.

@lifan0127
Copy link

Hi @filipesilva I also encountered this issue today. If I create the service in the "app/shared" folder and then add it to main.ts, I will have the same 404 error for missing shared/index.js. However, if the service is placed in the "app" folder as you did, it will build and load correctly via ng build --prod.

ng new testproj
cd testproj
ng g service shared/my-test-service

main.js

import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { TestprojAppComponent, environment } from './app/';
import { MyTestServiceService } from './app/shared';

if (environment.production) {
  enableProdMode();
}

bootstrap(TestprojAppComponent, [
  MyTestServiceService
]);

Error:

GET http://localhost:8000/app/shared/index.js 404 (File not found)

My system:

angular-cli: 1.0.0-beta.5
node: 6.2.0
os: win32 x64

@filipesilva
Copy link
Contributor

Hi @lifan0127, beta.6 should have a broader fix for that issue via #1028, but meanwhile there is a solution in #953.

@lifan0127
Copy link

Thanks @filipesilva I did come up with the same solution of importing this service from 'app/index.ts' which fixed the problem. Look forward to beta 6!

@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants