angular / angular/angularfire

Function deployment not uploading referenced package.json file when built with @angular/fire:deploy

Open
#3,283 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
7.8k
Forks
2.2k
Avg merge
22h 28m
Merged PRs (30d)
6

Description

### Version info

**Angular:** 14.2.0

**Firebase:** 11.15.0

**AngularFire:** 7.4.1

**Other (e.g. Ionic/Cordova, Node, browser, operating system):**

### How to reproduce these conditions
Use `@angular/fire:deploy` for an Angular Universal app

**Failing test unit, Stackblitz demonstrating the problem**

**Steps to set up and reproduce**
Use an Nx workspace and add Angular Universal, then include `@angular/fire:deploy` builder (in Nx terms "executor") in `project.json`:
```json
"deploy": {
"executor": "@angular/fire:deploy",
"options": {
"ssr": true,
"firebaseProject": "my-project",
"functionsNodeVersion": 16,
"firebaseHostingSite": "my-site"
},
"configurations": {
"production": {
"browserTarget": "my-app:build:production",
"serverTarget": "my-app:server:production"
}
}
},
```
This generates a production build in the `dist` folder with the following structure:
```
dist /
my-app /
dist /
my-app /
browser
server
node_modules /
index.js
package.json
package-lock.json
```

In the `package.json` file that resides in the `dist` folder is a reference like so:
```
{
// [...]
"my-app": "file:../.."
}
```
The firebase configuration is set up like so:
```json
{
"functions": [
{
"source": "dist/my-app",
"codebase": "default",
"ignore": ["node_modules"]
}
]
}
```

Upon running `firebase deploy --only functions` it errors out (see section below for logs). It seems files outside the `source` are not uploaded to firebase functions and so `@angular/fire:deploy` can't be used to deploy functions.

I can confirm this with the following steps. I remove the line `"my-app": "file:../.."` from the generated `package.json` and remove the `node_modules` and `package-lock.json` in the `dist` folder. Then I run `npm install` in the `dist` folder. When done, I run `firebase deploy --only functions` and it works.

**Sample data and security rules**

### Debug output

** Errors in the JavaScript console **
When running `firebase deploy --only functions` the following output is generated:
```
Build failed: npm ERR! code EUSAGE
npm ERR!
npm ERR! The `npm ci` command can only install with an existing package-lock.json or
npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
npm ERR! later to generate a package-lock.json file, then try again.
npm ERR!
npm ERR! Clean install a project
npm ERR!
npm ERR! Usage:
npm ERR! npm ci
npm ERR!
npm ERR! Options:
npm ERR! [--no-audit] [--foreground-scripts] [--ignore-scripts]
npm ERR! [--script-shell ]
npm ERR!
npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
npm ERR!
npm ERR! Run "npm help ci" for more info

npm ERR! A complete log of this run can be found in:
npm ERR!

Functions deploy had errors with the following functions:
ssr(us-central1)
i functions: cleaning up build files...

Error: There was an error deploying functions
```

** Output from `firebase.database().enableLogging(true);` **

** Screenshots **

### Expected behavior
`@angular/fire:deploy` should generate output that can be uploaded to functions as is.

### Actual behavior
Functions cannot be deployed because the reference in the generated `package.json` is outside the `source` folder.

Contributor guide

Open the contributing guide

Research direction

Start with the @angular/fire:deploy builder configuration in project.json and inspect the generated dist/my-app/package.json, especially its file:../.. reference. Reproduce with firebase deploy --only functions and verify that the generated output can be deployed without referencing files outside the configured functions source.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, firebase, node.js, typescript
Domain
backend, cloud, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.