angular-cli: Can't build to parent outDir folder with 1.5.4

Versions

Angular CLI: 1.5.4
Node: 6.11.2
OS: win32 x64 (Win10)
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-webworker
... platform-webworker-dynamic, router, tsc-wrapped

@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.4
@angular/material: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.21
@angular-devkit/schematics: 0.0.37
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.4
@schematics/angular: 0.1.7
typescript: 2.3.4
webpack: 3.8.1

Repro steps

  • Set apps[0].outDir as "../dist" on .angular-cli.json
  • run ng b

Observed behavior

Only a error message: An asset cannot be written to a location outside the project.

Desired behavior

Build the project without problem.

Mention any other details that might be useful (optional)

We have tried to add allowOutsideDir to ours assets configuration on cli config, but doesn’t work. Is this the expected behaviour? I don’t found related information about it in de64b86 or #8122 😦

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 30
  • Comments: 32 (3 by maintainers)

Most upvoted comments

Same problem here. I can’t believe a major functionality of the CLI, “ng b”, doesn’t work after an update… Downgrade to 1.5.3…

Patching the 1.5.4 with fix in #8630 solve the problem, so just wait for the next release.

Damn, no wonder, I was like, it was working at work before the weekend, why is it not working at home?

I was scratching my head so much I am almost bald now.

This error is still occurring in 1.7.4. It’s highly problematic for a project I’m working on since I have around 5GB worth of images to serve and placing them in the assets folder causes the ng serve to crash.

For anyone looking to fix it locally, edit …/node_modules/@angular/cli/models/webpack-configs/common.js. The code starts at line 99. I’m not going to make a pull request to fix it because I don’t know if there is a legit reason for this functionality (although it seems odd to me and as others have mentioned, it’s not really a security thing).

#8630 solves the problem. Until the fix is released, it’s better to lock the cli version at 1.5.3.

@hansl can you have a look please?

@Sanafan You could look into it. It’s marked as an easy to fix regression

when will this be fixed …

Same issue with 1.6.3 and 1.6.5 when running ‘ng build’

      "assets": [{
        "input": "./assets/",
        "glob": "**/*",
	    	"output": "../EcView/WebContent/dist/assets",
        "allowOutsideOutDir": true
      }],

An asset cannot be written to a location outside the project.

can u share ur config and error message?

I’m not sure this covers every possible scenario, but the obvious thing to do is use an npm script to copy things post-build

package,json

  "scripts": {
    ...
    "build-prod": "ng build --prod --stats-json",
    "postbuild-prod": "copyfiles ./dist/**/* c:/dist",
  },

Footnote - ‘postbuild-prod’ runs automatically after ‘build-prod’.


This is quoted from issue 8122, and seems fair enough as a precaution.

This is done so that people don’t overwrite their app by mistake (or a malicious app overwrites system files).

So, requiring the developer to specifically copy via script achieves both objectives.