Hello Everyone, I just want to share my problem maybe someone could help, I’m new on netlify, I deployed my first function using node.js on netlify, the project work well on my local machine by netlify-lambda serve, but when I deployed it, I couldn’t read a json file loacated on ./src/all/channels.json file, I spent a lot of time and effort looking for solation but until now I found nothing I almost give up.
Thank you in advance, here’s my netlify domain: app.netlify.com
How are you reading the JSON file in your function? If you are using readFileSync or other fs method you will need to use the included_files configuration option in the project’s netlify.toml. E.g.
Hi @coelmay This Method it’s work but not 100% I included the file path in .toml file as the first example but I still couldn’t read from the file, what kind of work is importing the file as the second example that you share with me but I still couldn’t read from the json file directly I could only get it’s content through the testJSON variable
Hi @hrishikesh Thank you for support, I tried to change in the .toml file as you suggested but unfortunately It won’t to build anymore It gives an error also when I tried to deploy it, the deployment failed and return :
Well, can’t comment much without seeing your site. You’ve shared an irrelevant part of your deploy log, which doesn’t help much and lack of any site address in this thread is a blocker.
Here’s my website: https://pro-tv.netlify.app/
I have an empty index.htm on it, I’ll be glad to share anything would help solving this issue.
and This’s the whole Deploy log:
11:52:07 AM: Build ready to start
11:52:08 AM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
11:52:08 AM: build-image tag: v4.10.1
11:52:08 AM: buildbot version: 37262c48b1f3cfa88c6caed707d29b19aef6a5a7
11:52:08 AM: Fetching cached dependencies
11:52:08 AM: Starting to download cache of 115.3MB
11:52:09 AM: Finished downloading cache in 1.151917165s
11:52:09 AM: Starting to extract cache
11:52:10 AM: Finished extracting cache in 824.861672ms
11:52:10 AM: Finished fetching cache in 2.037069768s
11:52:10 AM: Starting to prepare the repo for build
11:52:11 AM: Preparing Git Reference refs/heads/main
11:52:12 AM: Parsing package.json dependencies
11:52:13 AM: Starting build script
11:52:13 AM: Installing dependencies
11:52:13 AM: Python version set to 2.7
11:52:13 AM: Started restoring cached node version
11:52:13 AM: Finished restoring cached node version
11:52:14 AM: v16.17.0 is already installed.
11:52:14 AM: Now using node v16.17.0 (npm v8.15.0)
11:52:14 AM: Started restoring cached build plugins
11:52:14 AM: Finished restoring cached build plugins
11:52:14 AM: Attempting ruby version 2.7.2, read from environment
11:52:15 AM: Using ruby version 2.7.2
11:52:15 AM: Using PHP version 8.0
11:52:15 AM: No npm workspaces detected
11:52:15 AM: Started restoring cached node modules
11:52:15 AM: Finished restoring cached node modules
11:52:16 AM: Started restoring cached go cache
11:52:16 AM: Finished restoring cached go cache
11:52:16 AM: Installing Go version 1.17 (requested 1.17)
11:52:21 AM: unset GOOS;
11:52:21 AM: unset GOARCH;
11:52:21 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
11:52:21 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
11:52:21 AM: go version >&2;
11:52:21 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
11:52:21 AM: go version go1.17 linux/amd64
11:52:21 AM: Installing missing commands
11:52:21 AM: Verify run directory
11:52:22 AM:
11:52:22 AM: ────────────────────────────────────────────────────────────────
11:52:22 AM: Netlify Build
11:52:22 AM: ────────────────────────────────────────────────────────────────
11:52:22 AM:
11:52:22 AM: ❯ Version
11:52:22 AM: @netlify/build 27.17.1
11:52:22 AM:
11:52:22 AM: ❯ Flags
11:52:22 AM: baseRelDir: true
11:52:22 AM: buildId: 631dbdd74c3cfa000c563e72
11:52:22 AM: deployId: 631dbdd74c3cfa000c563e74
11:52:22 AM:
11:52:22 AM: ❯ Current directory
11:52:22 AM: /opt/build/repo
11:52:22 AM:
11:52:22 AM: ❯ Config file
11:52:22 AM: /opt/build/repo/netlify.toml
11:52:22 AM:
11:52:22 AM: ❯ Context
11:52:22 AM: production
11:52:22 AM:
11:52:22 AM: ────────────────────────────────────────────────────────────────
11:52:22 AM: 1. Build command from Netlify app
11:52:22 AM: ────────────────────────────────────────────────────────────────
11:52:22 AM:
11:52:22 AM: $ npm run build
11:52:22 AM: > tv-pro@1.0.0 build
11:52:22 AM: > ./node_modules/.bin/netlify-lambda build src
11:52:22 AM: netlify-lambda: Building functions
11:52:22 AM: TypeError: Cannot read properties of undefined (reading 'environment')
11:52:22 AM: at Object.exports.loadContext (/opt/build/repo/node_modules/netlify-lambda/lib/config.js:37:30)
11:52:22 AM: at webpackConfig (/opt/build/repo/node_modules/netlify-lambda/lib/build.js:87:24)
11:52:22 AM: at async Object.exports.run (/opt/build/repo/node_modules/netlify-lambda/lib/build.js:208:18)
11:52:22 AM:
11:52:22 AM: ────────────────────────────────────────────────────────────────
11:52:22 AM: "build.command" failed
11:52:22 AM: ────────────────────────────────────────────────────────────────
11:52:22 AM:
11:52:22 AM: Error message
11:52:22 AM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
11:52:22 AM:
11:52:22 AM: Error location
11:52:22 AM: In Build command from Netlify app:
11:52:22 AM: npm run build
11:52:22 AM:
11:52:22 AM: Resolved config
11:52:22 AM: build:
11:52:22 AM: command: npm run build
11:52:22 AM: commandOrigin: ui
11:52:22 AM: environment:
11:52:22 AM: - ACCESS_TOKEN
11:52:22 AM: - NETLIFY_GRAPH_TOKEN
11:52:22 AM: - ONEGRAPH_AUTHLIFY_TOKEN
11:52:22 AM: publish: /opt/build/repo/dist
11:52:22 AM: publishOrigin: ui
11:52:22 AM: functions:
11:52:22 AM: '*':
11:52:22 AM: included_files:
11:52:22 AM: - all/channels.json
11:52:22 AM: functionsDirectory: /opt/build/repo/functions
11:52:23 AM: Caching artifacts
11:52:23 AM: Started saving node modules
11:52:23 AM: Finished saving node modules
11:52:23 AM: Started saving build plugins
11:52:23 AM: Finished saving build plugins
11:52:23 AM: Started saving pip cache
11:52:23 AM: Finished saving pip cache
11:52:23 AM: Started saving emacs cask dependencies
11:52:23 AM: Finished saving emacs cask dependencies
11:52:23 AM: Started saving maven dependencies
11:52:23 AM: Finished saving maven dependencies
11:52:23 AM: Started saving boot dependencies
11:52:23 AM: Finished saving boot dependencies
11:52:23 AM: Started saving rust rustup cache
11:52:23 AM: Finished saving rust rustup cache
11:52:23 AM: Started saving go dependencies
11:52:23 AM: Finished saving go dependencies
11:52:23 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:52:23 AM: Creating deploy upload records
11:52:23 AM: Failing build: Failed to build site
11:52:23 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:52:24 AM: Finished processing build request in 15.455598943s
I’m newbie at Netlify platform I don’t know what build command in Netlify mean, if you give me an example I’ll be Thankful, it’ll be much easier for me