angularvercel

Error deploying angular app with scripts to Vercel


I am getting the below error

[ERROR] ENOENT: no such file or directory, open '/vercel/path0/src/js/external-script.js' [plugin angular-script-global]

angular.json

  "scripts": [
              "./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
              "./src/js/external-script.js"
]
             

local build works.


Solution

  • First move the "external-script.js" to the assets or public folder.

    Then make sure you have that folder added to the assets array of angular.json.

      "assets": ["/src/assets"],
    

    This will ensure your script is discoverable when angular builds the application.

    Reference Answer

    Then Reference that file from the scripts array of angular.json.

    "scripts": [
        "./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
        "./src/assets/external-script.js"
    ]