简体   繁体   中英

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?

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.

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)

我遇到了同样的错误 - 我试图从 dist 文件夹运行命令......当我改回项目的根文件夹时,它工作正常

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM