serverless / serverless

⚡ Serverless Framework – Use AWS Lambda and other managed cloud services to build apps that auto-scale, cost nothing when idle, and boast radically low maintenance.
https://serverless.com
MIT License
46.3k stars 5.69k forks source link

[windows][v4] serverless invoke local is failing to load handlers #12621

Closed cedric-vermeulen closed 2 days ago

cedric-vermeulen commented 1 week ago

Issue description

I did update to serverless V4 with success. If running serverless dev, I have no issue. But when i try to run serverless invoke local -f handler it does fail with this kind of issue:

image

I could pinpoint the exact location and fix.

In .serverless\releases\4.1.5\package\dist\sf-core.js Line 1025 i did change: path47.join(this.serverless.serviceDir,this.options.extraServicePath||"",handlerPath) to path47.join("file://",this.serverless.serviceDir,this.options.extraServicePath||"",handlerPath)

Of course it's a bit of a hack, I've seen in the file that we do handle file system more cleanly but I needed a quick fix.

I hope this is enough informations to help you fix the issue.

Service Overview

Service Overview

Service Path

E:\kkk\gestion\gestion.services\project-manager

Service Config

import type { AWS } from '@serverless/typescript';
import hello from '@functions/hello';
const serverlessConfiguration: AWS = {
  service: 'project-manager',
  org: 'slade',
  frameworkVersion: '4',
  plugins: [],
  provider: {
    name: 'aws',
    runtime: 'nodejs20.x',
    environment: {
      AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
      AWS_REGION: 'eu-west-1',
      AWS_ACCESS_KEY_ID: '$AWS_ACCESS_KEY_ID',
      AWS_SECRET_ACCESS_KEY: '$AWS_SECRET_ACCESS_KEY',
      NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000',
    },
  },
  functions: { hello },
  custom: {},
};
module.exports = serverlessConfiguration;

Thank you, Have a nice day,

Context

No response

eahefnawy commented 1 week ago

Thanks a lot for the detailed report @cedric-vermeulen ... We really appreciate such reports ❤️ ... I'll look into this.

NicoHinderling commented 4 days ago

I just wanted to +1 to this. I tried running a local command that worked in v3 and got the following stacktrace:

npm exec sls invoke local --function fireball --stage prod --data {"function": "nico"}

Warning: Using serverless deploy -f option only updates the function code and will not update CloudFormation stack (env variables included).
✖ ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/nicolashinderling/dev/emerge-pnpm-on-hold/backend/services/emerge/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/nicolashinderling/dev/emerge-pnpm-on-hold/backend/services/emerge/.serverless/build/src/fireball/fireball.js:224:2761
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadModule (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1025:9923)
    at async AwsInvokeLocal.invokeLocalNodeJs (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1025:9253)
    at async PluginManager.runHooks (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1028:9294)
    at async PluginManager.invoke (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1028:10064)
    at async PluginManager.run (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1028:10788)
    at async Serverless.run (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1035:10442)
    at async runFramework (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1079:2314)
    at async route (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1088:14692)
    at async Object.run2 [as run] (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1088:15090)
    at async run3 (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1088:16324)

✖ Exception encountered when loading /Users/nicolashinderling/dev/emerge-pnpm-on-hold/backend/services/emerge/.serverless/build/src/fireball/fireball
ServerlessError2: Exception encountered when loading /Users/nicolashinderling/dev/emerge-pnpm-on-hold/backend/services/emerge/.serverless/build/src/fireball/fireball
    at AwsInvokeLocal.invokeLocalNodeJs (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1025:9347)
    at async PluginManager.runHooks (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1028:9294)
    at async PluginManager.invoke (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1028:10064)
    at async PluginManager.run (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1028:10788)
    at async Serverless.run (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1035:10442)
    at async runFramework (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1079:2314)
    at async route (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1088:14692)
    at async Object.run2 [as run] (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1088:15090)
    at async run3 (file:///Users/nicolashinderling/.serverless/releases/4.1.5/package/dist/sf-core.js:1088:16324)

For help, try the following:
  • Run the command again with the "--debug" option
  • Run "serverless support"
  • Review the docs: https://www.serverless.com/framework/docs/

npm verb exit 1
npm verb code 1
NicoHinderling commented 2 days ago

@eahefnawy was this change released? I tried running npx serverless update and am still seeing errors when running my local invoke command (slightly different error message but still similar... I can post the error logs if needed)

eahefnawy commented 1 day ago

Yeah it was released. What's the new error you're seeing? 🤔

NicoHinderling commented 1 day ago

Hey @eahefnawy my apologies, I had something messed up locally. I re-setup my local and my npx invoke local is working now! Sorry about that!

eahefnawy commented 18 hours ago

Great to hear! 🙌