-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Import issue in Nestjs #35
Comments
Hmmm... I'm not really a fan of supporting outdated import systems in new projects. A PR for a separate commonJs build is welcome, but I won't put the effort to support legacy stuff. Please just pay attention that it has to be a separate build, otherwise you will break all existing integrations using normal modules. |
@dagnelies Is this also a reason why the package doesn't work for me?
Then importing it in my Nuxt 2 project
gives me this error Node v16. I also tried the Arch0125`s fork |
@dagnelies no matter I use commonjs or es6 or nodenext, it doesn't work |
Node 16 has already reached EOL and nuxt2 follows in half a year. It's time to move on to ES modules. I can only repeat myself.
If you really want that commonJs "require",you are welcome to make a PR for a separate build. It may even be relatively straightforward to do. |
Is it possible to have a build in CommonJS? |
Well, this is like asking for Internet Explorer 8 support. Native JS modules are supported since Node 8+. |
What about:
Then
Have you tried that? I guess it might complain though because this will import everything, including the client side which relies on the window object. |
I have tried it btw, it's not a solution. NestJS wants CommonJS build. :/ I have spent like 3 hours trying this method, it's not a solution. |
I've successfully integrated this functionality into NestJS without encountering any issues. The key is to leverage "dynamic import," which is a built-in feature, eliminating the need for any additional modules to be installed. In my controller, I imported the module using dynamic import as shown below: const FIDOResponse = JSON.parse(req.body.credential);
console.log(FIDOResponse);
console.log("headers: " + `https://${headers.host}`);
import("@passwordless-id/webauthn").then(async(module) => {
const { server } = module;
console.log("nodejs said, module was loaded successfully")
const registrationParsed = await server.verifyRegistration(FIDOResponse, {
challenge: session.TEMP_Challenge,
origin: `https://${headers.host}`,
})
console.log(registrationParsed);
}).catch((error) => {
// Handle any import errors
console.log(error);
}); Originally, this resulted in around 10 lines of errors, starting with the one you mentioned. To resolve this issue, I made modifications to my tsconfig.json to enable the use of dynamic imports. Specifically, I added the following settings: "moduleResolution": "NodeNext",
"target": "ESNext", For clarity, here's the complete tsconfig.json file: {
"compilerOptions": {
"module": "CommonJS",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ESNext", // <- This line was modified
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"moduleResolution": "NodeNext" // <- This line was modified
}
} |
Error
Code
// both doesn't work and give same error
tsconfig
// can't change this to ES6 which result into issue for all other imports
Regenerate issue
install nestjs
install '@passwordless-id/webauthn';
try to import and run
The text was updated successfully, but these errors were encountered: