Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when bundled #4

Open
kernwig opened this issue Oct 4, 2022 · 1 comment
Open

Fails when bundled #4

kernwig opened this issue Oct 4, 2022 · 1 comment

Comments

@kernwig
Copy link

kernwig commented Oct 4, 2022

Works locally, but the odd way the code tries to load the noswearing module does not work when bundled with esbuild and deployed into an AWS Lambda. (I expect the trouble is when bundling, not the ultimate run environment.)

ERROR	Uncaught Exception 	
{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '/var/task/src/infrastructure/player-api/custom_module/noswearing'\nRequire stack:\n- /var/task/src/infrastructure/player-api/register-player-lambda.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '/var/task/src/infrastructure/player-api/custom_module/noswearing'",
        "Require stack:",
        "- /var/task/src/infrastructure/player-api/register-player-lambda.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:951:17)",
        "    at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)",
        "    at async start (file:///var/runtime/index.mjs:1137:23)",
        "    at async file:///var/runtime/index.mjs:1143:1"
    ]
}
@kernwig
Copy link
Author

kernwig commented Oct 4, 2022

Reproducible example:

setup

% npm init
% npm install typescript esbuild super-profanity

try.ts

import { profanity } from "super-profanity";

console.log(profanity("words yo"));

Bundle on CLI with esbuild:

% npx esbuild try.ts --bundle --outfile=try.js --platform=node

Run:

% node try.js
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '/Users/adam/dev/profanity/custom_module/noswearing'
Require stack:
- /Users/adam/dev/profanity/try.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at node_modules/super-profanity/dist/profanity.js (/Users/adam/dev/profanity/try.js:184:26)
    at __require (/Users/adam/dev/profanity/try.js:8:50)
    at Object.<anonymous> (/Users/adam/dev/profanity/try.js:288:38)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/adam/dev/profanity/try.js' ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant