Gasegamer / super-profanity

An advanced profanity filter based on phonetics and normal detection that detects swears in 27 different languages!
Mozilla Public License 2.0
16 stars 2 forks source link

Fails when bundled #4

Open kernwig opened 1 year ago

kernwig commented 1 year ago

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 commented 1 year ago

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' ]
}