floydspace / serverless-esbuild

💨 A Serverless framework plugin to bundle JavaScript and TypeScript with extremely fast esbuild
MIT License
452 stars 138 forks source link

Failure: Cannot find module '../../dialects/sqlite3/index.js' #211

Closed feryardiant closed 2 years ago

feryardiant commented 3 years ago

Hi, I am new here and experiencing this issue which is I have no clue what's just happened 😅

My project is using knex with postgres or sqlite as main database, but when I ran sls offline and trying to accessing the url, my terminal show me this error.

$> sls offline --stage dev

Serverless: Using provider credentials, configured via dashboard: https://app.serverless.com/feryardiant/apps/my-app/...
Serverless: Compiling to node14 bundle with esbuild...
Serverless: Compiling with concurrency: Infinity
Serverless: Compiling completed.
offline: Starting Offline: stage/region.
offline: Offline [http for lambda] listening on http://localhost:3002
offline: Function names exposed for local invocation by aws-sdk:
        * test: webar-api-dev-test
offline: [object Object]

┌────────────────────────────────────────────────────────────────────────┐
│                                                                        │
│   GET | http://localhost:3001/dev                                      │
│   POST | http://localhost:3001/2015-03-31/functions/test/invocations   │
│                                                                        │
└────────────────────────────────────────────────────────────────────────┘

offline: [HTTP] server ready: http://localhost:3001 🚀
offline:
offline: Enter "rp" to replay the last request

offline: GET /dev (λ: test)
offline: Failure: Cannot find module '../../dialects/sqlite3/index.js'
Require stack:
- D:\path\to\project\backend\.esbuild\.build\functions\index.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\handler-runner\in-process-runner\InProcessRunner.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\handler-runner\in-process-runner\index.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\handler-runner\HandlerRunner.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\handler-runner\index.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\LambdaFunction.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\LambdaFunctionPool.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\Lambda.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\lambda\index.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\ServerlessOffline.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\index.js
- D:\path\to\project\node_modules\.pnpm\serverless-offline@8.2.0\node_modules\serverless-offline\dist\main.js
- D:\path\to\project\node_modules\.pnpm\serverless@2.64.1\node_modules\serverless\lib\classes\PluginManager.js
- D:\path\to\project\node_modules\.pnpm\serverless@2.64.1\node_modules\serverless\lib\Serverless.js
- D:\path\to\project\node_modules\.pnpm\serverless@2.64.1\node_modules\serverless\scripts\serverless.js
- D:\path\to\project\node_modules\.pnpm\serverless@2.64.1\node_modules\serverless\bin\serverless.js

Appreciate any helps, Thank you in advance.

Info

Operating System:    win32
Node Version:        14.18.0
Framework Version:   2.64.1 (local)
Plugin Version:      5.5.0
SDK Version:         4.3.0
Components Version:  3.17.1
floydspace commented 3 years ago

Hi @feryardiant could you show your config? most probably you need to mark sqlite3 as external

feryardiant commented 3 years ago

most probably you need to mark sqlite3 as external

Tried your suggestion and seems it solve my issue

 custom:
   esbuild:
     minify: true
+    exclude:
+      - sqlite3
     watch:
       pattern: ['./main.js', '(lib|functions)/**/*.js'] # default .
       ignore: [.build, 'dist', 'node_modules', '.serverless']

Thank you

feryardiant commented 3 years ago

My apology for reopening this issue. Because I got another error like these

Error: Cannot find module '../../dialects/sqlite3/index.js'
Require stack:
- D:\path\to\project\backend\.esbuild\.build\functions\index.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\handler-runner\in-process-runner\InProcessRunner.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\handler-runner\in-process-runner\index.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\handler-runner\HandlerRunner.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\handler-runner\index.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\LambdaFunction.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\LambdaFunctionPool.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\Lambda.js
- D:\path\to\project\node_modules\serverless-offline\dist\lambda\index.js
- D:\path\to\project\node_modules\serverless-offline\dist\ServerlessOffline.js
- D:\path\to\project\node_modules\serverless-offline\dist\index.js
- D:\path\to\project\node_modules\serverless-offline\dist\main.js
- D:\path\to\project\node_modules\serverless\lib\classes\PluginManager.js
- D:\path\to\project\node_modules\serverless\lib\Serverless.js
- D:\path\to\project\node_modules\serverless\scripts\serverless.js
- D:\path\to\project\node_modules\serverless\bin\serverless.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at dB (D:\path\to\project\backend\.esbuild\.build\functions\index.js:38:5768)
    at Pr (D:\path\to\project\backend\.esbuild\.build\functions\index.js:38:6144)
    at Object.<anonymous> (D:\path\to\project\backend\.esbuild\.build\functions\index.js:38:6888)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at D:\path\to\project\node_modules\serverless-offline\dist\lambda\handler-runner\in-process-runner\InProcessRunner.js:157:133
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async InProcessRunner.run (D:\path\to\project\node_modules\serverless-offline\dist\lambda\handler-runner\in-process-runner\InProcessRunner.js:157:9)

And here my serverless.yml file

https://github.com/feryardiant/learn-webar/blob/64c5577b4a8e61faf2ce1cee5eecd0d6eaaf5d7a/backend/serverless.yml#L28-L36

Also I noticed this error when I try invoking the end-point after deployment https://github.com/feryardiant/learn-webar/issues/8

samchungy commented 3 years ago

Exclude is different to External, have you tried External like floydspace suggested?

feryardiant commented 3 years ago

@samchungy yes I have and the result is remain the same image

samchungy commented 3 years ago

Looks like an issue with knex

https://github.com/evanw/esbuild/issues/473

floydspace commented 3 years ago

we have a closed issue related to knex https://github.com/floydspace/serverless-esbuild/issues/114 maybe @feryardiant you can find a solution there

samchungy commented 2 years ago

Closing. @feryardiant please reopen if you still have an issue