Giter Site home page Giter Site logo

Comments (3)

sturtevant avatar sturtevant commented on July 29, 2024 2

I just ran into this when it broke TypeORM config file resolution (app-root-path is a dependency of TypeORM). I think the reason it is breaking is that /workspace/node_modules is included in globalPaths. This bypasses the correct answer (/workspace) and drops down into the alternate resolution logic that produces the incorrect app root based on the value of require.main.filename.

In case it helps, here are some (sanitized) values from the runtime of my Google Cloud Function:

process.platform: "linux"

process.env: {
  "GCF_BLOCK_RUNTIME_nodejs6": "410",
  "NO_UPDATE_NOTIFIER": "true",
  "FUNCTION_TARGET": "main",
  "NODE_PATH": "/workspace/node_modules",
  "NODE_ENV": "production",
  "PWD": "/workspace",
  "HOME": "/root",
  "DEBIAN_FRONTEND": "noninteractive",
  "PORT": "8080",
  "SHLVL": "1",
  "GAE_RUNTIME": "nodejs14",
  "FUNCTION_SIGNATURE_TYPE": "http",
  "PATH": "/workspace/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  "_": "/layers/google.nodejs.functions-framework/functions-framework/node_modules/.bin/functions-framework"
}

process.versions: {
  "node": "14.16.0",
  "v8": "8.4.371.19-node.18",
  "uv": "1.40.0",
  "zlib": "1.2.11",
  "brotli": "1.0.9",
  "ares": "1.16.1",
  "modules": "83",
  "nghttp2": "1.41.0",
  "napi": "7",
  "llhttp": "2.1.3",
  "openssl": "1.1.1j",
  "cldr": "37.0",
  "icu": "67.1",
  "tz": "2020a",
  "unicode": "13.0"
}

require('module').globalPaths: [
  "/workspace/node_modules",
  "/root/.node_modules",
  "/root/.node_libraries",
  "/usr/lib/node"
]

require.main.filename: "/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/index.js"

Ultimately my workaround fix was to set the APP_ROOT_PATH environment variable in the Cloud Function to /workspace to get the correct behavior. This isn't very intuitive, however, and is likely to trip up a lot of folks who (like me) don't even realize that app-root-path is in their dependency chain.

Perhaps a short-circuit (similar to the one already in place for AWS Lambda) could be implemented to disregard the fact that /workspace/node_modules is in the globalPaths whenever the string '@google-cloud/functions-framework' was in the path of require.main.filename?

from node-app-root-path.

Michaelp1994 avatar Michaelp1994 commented on July 29, 2024

I seem to be running into the same issue trying to get TypeORM working with Serverless-Stack Live Lamda Development for AWS Lambda functions.
I get the following error:
ERROR Runtime.UnhandledPromiseRejection: TypeError: Cannot read properties of undefined (reading 'filename')
Not sure if it has to do with ESBuild being used.
@sturtevant your suggestion of setting APP_ROOT_PATH for the lambda environment seems to have hot-fixed the issue my issue as well.

from node-app-root-path.

FFdhorkin avatar FFdhorkin commented on July 29, 2024

I seem to be running into the same issue trying to get TypeORM working with Serverless-Stack Live Lamda Development for AWS Lambda functions. I get the following error: ERROR Runtime.UnhandledPromiseRejection: TypeError: Cannot read properties of undefined (reading 'filename') Not sure if it has to do with ESBuild being used. @sturtevant your suggestion of setting APP_ROOT_PATH for the lambda environment seems to have hot-fixed the issue my issue as well.

I'm having a similar issue with serverless-esbuild / serverless-offline...

  • the resolved variable in app-root-path's resolve.js is resolving to '/my/path/to/project/.esbuild/.build/src'
  • the appRootPath is being returned as '/my/path/to/project/node_modules/serverless-offline/src/lambda/handler-runner/worker-thread-runner'
  • and what I want would be /my/path/to/project/

I have opened a PR (#55) to make esbuild play nice

from node-app-root-path.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.