serah
serah

Reputation: 2127

ng build --prod gives no such file or directory error for the specified outDir in angular-cli.json

My angular project fails to build when I try to build for prod (ng build --prod). Please note ng build seems to work fine.

I get the below error when I try to build with --prod option

Error: ENOENT: no such file or directory, mkdir 'C:\dev\workspaces\intellij-workspaces\myproject\web\target\frontend'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:922:18)

I have set my angular-cli outDir as below

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "web"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "../../../target/frontend",
      "deployUrl": "myproject-dashboard/",
      "assets": [
        "assets",
        "favicon.ico"
      ],

My package.json and angular-cli.json files are present under myproject/web/src/main/frontend

So, ideally based on the relative path set for outDir in angular-cli.json, I would expect a folder called target to be created under myproject/web folder and all my build output to be available there.

Please can you let me know if I should be creating the target folder manually or it there a way to tell angular-cli to create it automatically?

Upvotes: 5

Views: 5390

Answers (3)

Datum Geek
Datum Geek

Reputation: 1568

i got the same error - i was trying to run the command from the dist folder... when i changed back to the root folder of the project, and then it worked fine

Upvotes: -1

Ivan Gammel
Ivan Gammel

Reputation: 662

It's likely that you have some other problem in your code, which gots hidden by subsequent exception from the webpack, as described in this ticket:

https://github.com/angular/angular-cli/issues/7203

What's going on there? Build fails on compilation and thus does not create your output directory, but then CLI still performs other steps, one of which (the extraction of library licenses by webpack) requires that output directory shall exist. That step fails and get logged instead of the root cause.

Try adding --no-extract-licenses option to your ng build -prod command. This worked for me with exactly the same error as in your case.

Upvotes: 3

user4676340
user4676340

Reputation:

I had this problem too, what I did to resolve that is add this in my package.json file :

"scripts": {
  // ...
  "build": " mkdir dist && ng build --prod"
},

(given that your dest folder is dist)

Upvotes: 0

Related Questions