MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 137 forks source link

Added "type":"module" to package.json #229

Closed edwindj closed 2 years ago

edwindj commented 2 years ago

Thanks for this wonderful package!

I am using vite 3.0 to build my projects and vite complains that this package appears to be an ESM module, but does not state so in the package.json

vite 3.0:

@simplewebauthn/browser doesn't appear to 
be written in CJS, but also doesn't appear to 
be a valid ES module

Adding the "type":"module" in package.json fixes that.

MasterKale commented 2 years ago

@edwindj Thank you for the submission, I'm surprised no one's mentioned this before. It definitely makes sense to add this bit to the browser package.

MasterKale commented 2 years ago

browser tests are failing with the following error:

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/runner/work/SimpleWebAuthn/SimpleWebAuthn/packages/browser/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/runner/work/SimpleWebAuthn/SimpleWebAuthn/packages/browser/jest.config.js:1:20
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
    at async requireOrImportModule (/home/runner/work/SimpleWebAuthn/SimpleWebAuthn/node_modules/jest-util/build/requireOrImportModule.js:65:32)
    at async readConfigFileAndSetRootDir (/home/runner/work/SimpleWebAuthn/SimpleWebAuthn/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:132:22)
    at async readConfig (/home/runner/work/SimpleWebAuthn/SimpleWebAuthn/node_modules/jest-config/build/index.js:233:18)
    at async readConfigs (/home/runner/work/SimpleWebAuthn/SimpleWebAuthn/node_modules/jest-config/build/index.js:420:26)
    at async runCLI (/home/runner/work/SimpleWebAuthn/SimpleWebAuthn/node_modules/@jest/core/build/cli/index.js:132:59)

Can you take a crack at figuring out how Jest needs to be updated to resolve this? It may be as simple as changing jest.config.js to use import syntax instead.

MasterKale commented 2 years ago

@edwindj This is still worth merging in, if you're interested in solving that final Jest config issue (and rebasing on the latest master)

MasterKale commented 2 years ago

Superseded by #237