-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Issue with ES Modules in firebase functions #40
Comments
See #35 (comment) Does that help? |
I just tried that and it did give me a different error so it's a step in the right direction here is the tsconfig file
|
@dagnelies That issue did help, but we had to do some slight changes #35 (comment) 3 Changes: Sharing in case you're interested, we needed to modify the build script, update package.json, and create a function which handles dynamic imports 1. Modified build script// package.json
{
++
"type": "module",
"build": "esbuild src/index.ts --platform=node --bundle --target=es2022 --outfile=lib/index.js --external:util --external:cors",
...
} also updated // tsconfig.json
{
"compilerOptions": {
"module": "NodeNext",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "ESNext",
"moduleResolution": "NodeNext"
},
"compileOnSave": true,
"include": [
"src"
]
} 2. Created function to handle the dynamic import and return the parsedRegistrationsindex.ts // index.js
/**
* Handles the registration process for a user.
*
* @param {RegistrationEncoded} registration - The encoded registration data.
* @param {string} challenge - The challenge string.
* @return {RegistrationParsed} The credential object for the registered user.
*/
async function handleRegistration(
registration: RegistrationEncoded,
challenge: string,
) {
// Import the webauthn module
import("@passwordless-id/webauthn").then(async (module) => {
const {server} = module;
console.log("nodejs said, module was loaded successfully");
const registrationParsed: RegistrationParsed =
await server.verifyRegistration(registration, {
challenge: challenge,
origin: origin,
});
return registrationParsed;
}).catch((error) => {
// Handle any import errors
console.log(error);
return null;
});
} 3. Return credentialconst credential = await handleRegistration(registration, challenge);
return credential; Now the packages work fine |
Thanks for the detailed workaround. 👍 |
Current behavior:
Works fine in express in a traditional nodejs app
When deployed to firebase, tried both ts and vanilla js, getting this error. Have tried a number of workaround
Errors
Also got this one
code: 'ERR_REQUIRE_ESM'
The text was updated successfully, but these errors were encountered: