Skip to content

ng eject breaks asset loading #9436

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

Closed
lifenautjoe opened this issue Jan 30, 2018 · 5 comments
Closed

ng eject breaks asset loading #9436

lifenautjoe opened this issue Jan 30, 2018 · 5 comments
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix

Comments

@lifenautjoe
Copy link

lifenautjoe commented Jan 30, 2018

Versions


    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/

Angular CLI: 1.6.6 (e)
Node: 8.1.2
OS: darwin x64
Angular: 5.2.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.6
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.6
@schematics/angular: 0.1.17
typescript: 2.6.2
webpack-dev-server: 2.11.1
webpack: 3.10.0

Repro steps

Step 1

Include an asset

app/index.html

// ..
                <img src="/assets/images/logo.png">
// ..

Step 2

Run ng serve

ng serve

Step 3

Observe the image is loaded correctly

Step 4

Eject the project

ng eject

Step 5

Run the project with the npm command

npm start

Observed behavior

The image is no longer loaded correctly.

logo.png:1 GET http://localhost:4200/assets/images/logo.png 404 (Not Found)

Desired behavior

The image is loaded in the same manner that the unejected project does.

EDIT

I have pinpointed the issue.
The ng eject command creates the given CopyWebpackPublic config

new CopyWebpackPlugin([
            {
                "context": "src",
                "to": "",
                "from": {
                    "glob": "src/assets/**/*",
                    "dot": true
                }
            },
            {
                "context": "src",
                "to": "",
                "from": {
                    "glob": "src/favicon.ico",
                    "dot": true
                }
            }
        ], {
            "ignore": [
                ".gitkeep",
                "**/.DS_Store",
                "**/Thumbs.db"
            ],
            "debug": "warning"
        })

The problem is that the paths for assets and favicon.ico now contain the src/ directory.
When renaming them to "assets/**/*" and "favicon.ico" it all works.

@lifenautjoe lifenautjoe changed the title ng eject breaks asset loading on dynamic route modules ng eject breaks asset loading Jan 30, 2018
@bampakoa
Copy link
Contributor

bampakoa commented Feb 1, 2018

I can confirm that it also happens in 1.6.7

@hansl hansl added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken labels Feb 1, 2018
@dragouf
Copy link

dragouf commented Feb 6, 2018

any fix ?

edit: ok, the fix was to remove 'src' from grlob path:

"from": {
      "glob": "src\\assets\\**\\*",
      "dot": true
}

to

"from": {
      "glob": "assets\\**\\*",
      "dot": true
}

@keego
Copy link

keego commented Aug 29, 2018

Just hit this with cli 1.6.7 as well; fixes mentioned above worked for me 👏

@clydin
Copy link
Member

clydin commented Sep 28, 2018

eject functionality is no longer available in the latest version (6.x+). For custom webpack configurations the following unofficial add-on is a suggested solution: https://github.com/manfredsteyer/ngx-build-plus

@clydin clydin closed this as completed Sep 28, 2018
@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
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

No branches or pull requests

7 participants