netlify / netlify/cli

Cannot read properties of undefined (reading 'mainFile')

Open
#6,785 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
TypeScript
Stars
1.9k
Forks
474
Avg merge
23h 30m
Merged PRs (30d)
53

Description

Describe the bug

When running netlify dev it crashes with node 20 and gives the error Warning: TypeError: Cannot read properties of undefined (reading 'mainFile')

netlify --version  
netlify-cli/17.26.0 linux-x64 node-v20.12.2
◈ Extracted function errorHandler from /home/chris/dev/prosopo/captcha-private/netlify/functions/errorHandler.zip.
undefined
 ›   Warning: TypeError: Cannot read properties of undefined (reading 'mainFile')
 ›       at FunctionsRegistry.registerFunction (file:///home/user/.nvm/versions/node/v20.12.2/lib/node_modules/netlify-cli/dist/lib/functions/registry.js:320:80)
 ›       at async file:///home/user/.nvm/versions/node/v20.12.2/lib/node_modules/netlify-cli/dist/lib/functions/registry.js:413:13
 ›       at async Promise.all (index 1)
 ›       at async FunctionsRegistry.scan (file:///home/user/.nvm/versions/node/v20.12.2/lib/node_modules/netlify-cli/dist/lib/functions/registry.js:374:32)
 ›       at async startFunctionsServer (file:///home/user/.nvm/versions/node/v20.12.2/lib/node_modules/netlify-cli/dist/lib/functions/server.js:279:5)
 ›       at async BaseCommand.dev (file:///home/user/.nvm/versions/node/v20.12.2/lib/node_modules/netlify-cli/dist/commands/dev/dev.js:138:31)
 ›       at async BaseCommand.parseAsync (/home/user/.nvm/versions/node/v20.12.2/lib/node_modules/netlify-cli/node_modules/commander/lib/command.js:935:5)
 ›       at async file:///home/user/.nvm/versions/node/v20.12.2/lib/node_modules/netlify-cli/bin/run.js:27:3

Main file is actually present on the function definition:

errorHandler NetlifyFunction {
  buildError: null,
  srcFiles: Set(0) {},
  blobsContext: {
    deployID: '0',
    edgeURL: 'http://localhost:33031',
    siteID: 'unlinked',
    token: '*****',
    uncachedEdgeURL: 'http://localhost:33031',
    primaryRegion: 'dev'
  },
  config: {
    functionsDirectory: '/home/user/dev/project/netlify/functions',
    functionsDirectoryOrigin: 'config',
    build: {
      environment: {},
      processing: [Object],
      services: {},
      base: undefined,
      functions: '/home/user/dev/project/netlify/functions'
    },
    dev: {
      targetPort: 8081,
      command: 'npm run -w @org/project start'
    },
    redirectsOrigin: 'config',
    functions: { '*': {} },
    plugins: [],
    headers: [],
    redirects: [ [Object], [Object], [Object] ]
  },
  directory: '/home/user/dev/project/netlify/functions',
  mainFile: '/home/user/dev/project/netlify/functions/errorHandler.zip',
  name: 'errorHandler',
  displayName: 'errorHandler',
  projectRoot: '/home/user/dev/project/packages/org-website',
  runtime: [Module: null prototype] {
    getBuildFunction: [AsyncFunction: getBuildFunction],
    invokeFunction: [AsyncFunction: invokeFunction],
    invokeFunctionDirectly: [AsyncFunction: invokeFunctionDirectly],
    name: 'js',
    onDirectoryScan: [AsyncFunction: onDirectoryScan]
  },
  timeoutBackground: 900,
  timeoutSynchronous: 10,
  settings: {
    baseDirectory: undefined,
    command: 'npm run -w @org/project start',
    frameworkPort: 8081,
    dist: '/home/user/dev/project/packages/org-website',
    framework: undefined,
    env: undefined,
    pollingStrategies: [],
    useStaticServer: false,
    clearPublishDirectory: undefined,
    plugins: undefined,
    port: 8888,
    jwtSecret: 'secret',
    jwtRolePath: 'app_metadata.authorization.roles',
    functions: '/home/user/dev/project/netlify/functions',
    functionsPort: 38299,
    frameworkHost: '127.0.0.1'
  },
  isBackground: false,
  schedule: undefined
}
Steps to reproduce
  1. Run a netlify dev project with the above versions of node and netlify
  2. Specify functions in netlify/functions after having built them with from TS using netlify functions:build --src ./src --functions ./functions
Configuration
[dev]
targetPort = 8081
command = "npm run start"

[functions]
directory = "netlify/functions"


Environment
npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify-cli

  System:
    OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (8) x64 AMD FX(tm)-8350 Eight-Core Processor
    Memory: 14.28 GB / 31.30 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.12.2/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
  npmGlobalPackages:
    netlify-cli: 17.26.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with dist/lib/functions/registry.js at FunctionsRegistry.registerFunction, then reproduce with netlify dev using Node 20.12.2 and the provided netlify/functions configuration. Done means the built TypeScript function with a present mainFile starts without the undefined-property crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.