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

angular/cli 1.0.1 local JSON files #6158

Closed
brife opened this issue May 2, 2017 · 13 comments
Closed

angular/cli 1.0.1 local JSON files #6158

brife opened this issue May 2, 2017 · 13 comments
Assignees
Labels
needs: repro steps We cannot reproduce the issue with the information given

Comments

@brife
Copy link

brife commented May 2, 2017

Bug Report or Feature Request (mark with an x)

- [ X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.1
node: 6.10.0
os: darwin x64
@angular/animations: 4.1.0
@angular/common: 4.1.0
@angular/core: 4.1.0
@angular/forms: 4.1.0
@angular/http: 4.1.0
@angular/platform-browser: 4.1.0
@angular/platform-browser-dynamic: 4.1.0
@angular/router: 4.1.0
@angular/cli: 1.0.1
@angular/compiler-cli: 4.1.0
@angular/compiler: 4.1.0

Repro steps.

Up until @angular/cli 1.0.1, I was able to serve up test data from a local JSON file just by supplying the relative patch to the http component. For example, this.http.get(''/src/app/testdata/sopData.json'').map(...), would happily serve up the JSON from the root of the ng4 project. After upgrading to 1.0.1 this no longer works. I get a 404 on the http://localhost:4200/src/app/testdata/sopData.json request.

If I down grade to 1.0.0 it serves up the fine without error. I never really understood how not specifying a server translated to a straight file operation but I did take advantage of it. The fact that it doesn't work anymore doesn't feel like a bug, it feels more like a loophole that's been closed.

The log given by the failure.

GET http://localhost:4200/src/app/testdata/sopData.json 404 (Not Found)
scheduleTask
ZoneDelegate.scheduleTask
onScheduleTask
ZoneDelegate.scheduleTask
Zone.scheduleTask
Zone.scheduleMacroTask
(anonymous function)
send
(anonymous function)
Observable._trySubscribe
Observable.subscribe
MapOperator.call
Observable.subscribe
webpackJsonp.51.BaseSopPanelComponent.fetchData
webpackJsonp.51.BaseSopPanelComponent.ngOnInit
checkAndUpdateDirectiveInline
checkAndUpdateNodeInline
checkAndUpdateNode
debugCheckAndUpdateNode
debugCheckDirectivesFn
(anonymous function)
debugUpdateDirectives
checkAndUpdateView
callViewAction
execComponentViewsAction

Desired functionality.

Mention any other details that might be useful.

@avraampiperidis
Copy link

avraampiperidis commented May 3, 2017

same here, getting 404 for local css files.
GET http://192.168.0.8:4200/assets/css/index.css [HTTP/1.1 404 Not Found 3ms]
Also.
The resource from “http://192.168.0.8:4200/assets/css/index.css” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff)

@filipesilva
Copy link
Contributor

As far as I can tell, that's a 404, which means that the file just isn't there in builds. If you do ng build, is the file you're looking for there?

I'll have a look myself if you put up a simple repo showing this problem. I know that it seems an easy enough thing to reproduce, but there's a lot of different ways of doing it.

@filipesilva filipesilva self-assigned this May 8, 2017
@filipesilva filipesilva added the needs: repro steps We cannot reproduce the issue with the information given label May 8, 2017
@rj93
Copy link

rj93 commented May 8, 2017

I'm also getting this error:

GET http://localhost:4200/styles.css [HTTP/1.1 404 Not Found 1ms]
The resource from “http://localhost:4200/styles.css” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).[Learn More]

But when I change the style.css file, it is reflected in the browser.

Also getting the errors for zone.js, systemjs, and core-js

@Zvenigora
Copy link

From my understanding ng serve command works properly in version v1.0.0. However in case of version v1.0.1 and 1.0.2 the server returns 404. Please note that ng build works in all versions and the issue is related to the development server. Probably we already had the similar one (#5064). I prepared a sample repository having a component with an image and one JSON file. Please get the repo from https://github.com/Zvenigora/angular-cli-100-6158. I hope it helps.

@clydin
Copy link
Member

clydin commented May 10, 2017

@Zvenigora ng serve was actually working improperly prior to 1.0.1 and your example illustrates why. Your application will work via ng serve but fail after a build and deployment. Your assets are not properly defined in .angular-cli.json (or present in the preconfigured assets directory) so will not be copied to the output and will therefore be missing from the built output.

ng serve now more properly reflects the behavior of a deployment of the output of ng build. This also affected ng e2e which by default uses the ng serve functionality underneath; resulting in e2e tests passing when the app would actually fail when deployed.

@clydin
Copy link
Member

clydin commented May 10, 2017

@rj93 systemjs hasn't been used by the CLI for a very long time. Please ensure you are using the latest version and if your problem persists, please open a separate issue.

@filipesilva
Copy link
Contributor

@Zvenigora as per what @clydin said, you need to add data to the assets array if you want it to be served. It was a bug that the bare content of your src/ dir were all being served in 1.0.0.

@brife your problem seems to be the same as @Zvenigora.

@brife
Copy link
Author

brife commented May 10, 2017 via email

@Zvenigora
Copy link

@clydin as per your recommendation, I created a new branch assets in my sample repository, moved image and json-file into assets folder and updated assets array. Now it works. Thank you.

@nikhil5467
Copy link

Hi I am also getting the same error .I am not able to load images and fetch json data from the assets folder under src.
Help me on how I have to update the assets array.
It is showing like this.
"assets": [
"assets",
"favicon.ico"
],

@bhagathsing
Copy link

bhagathsing commented Jan 11, 2018

I got the same issue with adding json files. But that was fixed with below.
Instead : src/app/testdata/sopData.json
change to: asstes/testdata/sopData.json // It means testdata folder should be in assets folder

It is working fine for me

@jhourlad
Copy link

jhourlad commented Mar 5, 2018

Moving all static assets to assets is not solution. Some files essentially need to be in the root folder (e.g. robots.txt, sitemap.xml, etc.)

@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 8, 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

9 participants