Site works locally but failing to deploy on netlify via github

Hi. I’m having problems deploying my site to netlify through continuous deployment. I’m also using firebase. It works locally but it keeps having error when I build it on netlify. I think it has something to do with my firebase import on my index.js or my firebaseconfig but I don’t know what’s causing it.

my repo: GitHub - shanelgarcia/ecommerce-store

3:04:23 PM: Build ready to start
3:04:25 PM: build-image version: 122b31996ccaffd45d820a452d6227f8312110cc (focal)
3:04:25 PM: build-image tag: v4.5.3
3:04:25 PM: buildbot version: 7383bb8971c718de9618a700ec5049cb71af7102
3:04:25 PM: Building without cache
3:04:25 PM: Starting to prepare the repo for build
3:04:26 PM: No cached dependencies found. Cloning fresh repo
3:04:26 PM: git clone https://github.com/shanelgarcia/ecommerce-store
3:04:26 PM: Preparing Git Reference refs/heads/main
3:04:27 PM: Parsing package.json dependencies
3:04:28 PM: Starting build script
3:04:28 PM: Installing dependencies
3:04:28 PM: Python version set to 2.7
3:04:28 PM: Downloading and installing node v16.14.0...
3:04:29 PM: Downloading https://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz...
3:04:29 PM: Computing checksum with sha256sum
3:04:29 PM: Checksums matched!
3:04:32 PM: Now using node v16.14.0 (npm v8.3.1)
3:04:32 PM: Started restoring cached build plugins
3:04:32 PM: Finished restoring cached build plugins
3:04:32 PM: Attempting ruby version 2.7.2, read from environment
3:04:34 PM: Using ruby version 2.7.2
3:04:34 PM: Using PHP version 8.0
3:04:34 PM: Started restoring cached node modules
3:04:34 PM: Finished restoring cached node modules
3:04:34 PM: Installing NPM modules using NPM version 8.3.1
3:04:49 PM: added 321 packages, and audited 322 packages in 14s
3:04:49 PM: 79 packages are looking for funding
3:04:49 PM:   run `npm fund` for details
3:04:49 PM: found 0 vulnerabilities
3:04:49 PM: NPM modules installed
3:04:49 PM: Started restoring cached go cache
3:04:49 PM: Finished restoring cached go cache
3:04:49 PM: go version go1.16.5 linux/amd64
3:04:49 PM: go version go1.16.5 linux/amd64
3:04:49 PM: Installing missing commands
3:04:49 PM: Verify run directory
3:04:51 PM: ​
3:04:51 PM: ────────────────────────────────────────────────────────────────
3:04:51 PM:   Netlify Build                                                 
3:04:51 PM: ────────────────────────────────────────────────────────────────
3:04:51 PM: ​
3:04:51 PM: ❯ Version
3:04:51 PM:   @netlify/build 26.3.0
3:04:51 PM: ​
3:04:51 PM: ❯ Flags
3:04:51 PM:   baseRelDir: true
3:04:51 PM:   buildId: 620980673875320c78f743fe
3:04:51 PM:   deployId: 620980673875320c78f74400
3:04:51 PM: ​
3:04:51 PM: ❯ Current directory
3:04:51 PM:   /opt/build/repo
3:04:51 PM: ​
3:04:51 PM: ❯ Config file
3:04:51 PM:   No config file was defined: using default values.
3:04:51 PM: ​
3:04:51 PM: ❯ Context
3:04:51 PM:   production
3:04:51 PM: ​
3:04:51 PM: ────────────────────────────────────────────────────────────────
3:04:51 PM:   1. Build command from Netlify app                             
3:04:51 PM: ────────────────────────────────────────────────────────────────
3:04:51 PM: ​
3:04:51 PM: $ npm run build
3:04:52 PM: > sunnycoast-app@1.0.0 build
3:04:52 PM: > npx parcel build src/index.html
3:04:53 PM: Building...
3:04:53 PM: 🚨 Build failed.
3:04:55 PM: @parcel/core: Failed to resolve 'process' from
3:04:55 PM: './node_modules/@firebase/database/dist/index.esm2017.js'
3:04:55 PM:   /opt/build/repo/node_modules/@firebase/database/dist/index.esm2017.js:164:74
3:04:55 PM:     163 |  * Unless required by applicable law or agreed to in writing, software
3:04:55 PM:   > 164 |  * distributed under the License is distributed on an "AS IS" BASIS,
3:04:55 PM:   >     |    ^
3:04:55 PM:     165 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or imp
3:04:55 PM:     166 |  * See the License for the specific language governing permissions and
3:04:55 PM: [Error: ENOENT: no such file or directory, open '/opt/build/repo/node_modules/@firebase/database/src/realtime/WebSocketConnection.ts'] {
3:04:55 PM:   errno: -2,
3:04:55 PM:   code: 'ENOENT',
3:04:55 PM:   syscall: 'open',
3:04:55 PM:   path: '/opt/build/repo/node_modules/@firebase/database/src/realtime/WebSocketConnection.ts'
3:04:55 PM: }
3:04:55 PM: ​
3:04:55 PM: ────────────────────────────────────────────────────────────────
3:04:55 PM:   "build.command" failed                                        
3:04:55 PM: ────────────────────────────────────────────────────────────────
3:04:55 PM: ​
3:04:55 PM:   Error message
3:04:55 PM:   Command failed with exit code 1: npm run build
3:04:55 PM: ​
3:04:55 PM:   Error location
3:04:55 PM:   In Build command from Netlify app:
3:04:55 PM:   npm run build
3:04:55 PM: ​
3:04:55 PM:   Resolved config
3:04:55 PM:   build:
3:04:55 PM:     command: npm run build
3:04:55 PM:     commandOrigin: ui
3:04:55 PM:     environment:
3:04:55 PM:       - STOREFRONT_FIREBASE_API_KEY
3:04:55 PM:       - STOREFRONT_FIREBASE_APP_ID
3:04:55 PM:       - STOREFRONT_FIREBASE_AUTH_DOMAIN
3:04:55 PM:       - STOREFRONT_FIREBASE_DATABASE_URL
3:04:55 PM:       - STOREFRONT_FIREBASE_MESSAGING_SENDER_ID
3:04:55 PM:       - STOREFRONT_FIREBASE_PROJECT_ID
3:04:55 PM:       - STOREFRONT_FIREBASE_STORAGE_BUCKET
3:04:55 PM:     publish: /opt/build/repo/dist
3:04:55 PM:     publishOrigin: ui
3:04:55 PM: Caching artifacts
3:04:55 PM: Started saving node modules
3:04:55 PM: Finished saving node modules
3:04:55 PM: Started saving build plugins
3:04:55 PM: Finished saving build plugins
3:04:55 PM: Started saving pip cache
3:04:55 PM: Finished saving pip cache
3:04:55 PM: Started saving emacs cask dependencies
3:04:55 PM: Finished saving emacs cask dependencies
3:04:55 PM: Started saving maven dependencies
3:04:55 PM: Finished saving maven dependencies
3:04:55 PM: Started saving boot dependencies
3:04:55 PM: Finished saving boot dependencies
3:04:55 PM: Started saving rust rustup cache
3:04:55 PM: Finished saving rust rustup cache
3:04:55 PM: Started saving go dependencies
3:04:55 PM: Finished saving go dependencies
3:04:58 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:04:58 PM: Creating deploy upload records
3:04:58 PM: Failing build: Failed to build site
3:04:58 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
3:04:58 PM: Finished processing build request in 33.262736655s

Thank you.

Hey @chibisq

There’s a couple of things at play here.

The functions in src/js you’ll need to turn into Serverless Functions. The biggest reason for this is it is the only way to keep the API key, and other secret details secret. If you were to compile the JS as is, all this would get exposed on the front-end.

As you are using import, you will need to ensure you are using the esbuild bundler.

If you have any further questions or issue, do not hesitate to reply.

1 Like