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

Cannot run in typescript #22

Closed
bennettp123 opened this issue Feb 6, 2023 · 2 comments
Closed

Cannot run in typescript #22

bennettp123 opened this issue Feb 6, 2023 · 2 comments

Comments

@bennettp123
Copy link

To reproduce:

Attempt to run in typescript:

import stream from '@openpgp/web-stream-tools'

Error:

/Users/bennett/src/shared-infra/node_modules/.pnpm/@[email protected][email protected]/node_modules/@openpgp/web-stream-tools/lib/streams.js:1
import { isNode, isStream, isArrayStream, isUint8Array, concatUint8Array } from './util';
^^^^^^
    
SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1149:20)
    at Module._compile (node:internal/modules/cjs/loader:1190:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
    at Module.load (node:internal/modules/cjs/loader:1089:32)
    at Function.Module._load (node:internal/modules/cjs/loader:930:12)
    at Module.require (node:internal/modules/cjs/loader:1113:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/bennett/src/shared-infra/apps/shared/src/lib/github-actions-iam-accesskeys.ts:4:1)
    at Module._compile (node:internal/modules/cjs/loader:1226:14)

In #1, it was suggested that the right way to consume this module is to import it from openpgp

npm i openpgp
require('openpgp').stream

Is that still the recommended method? openpgp no longer exports stream, see openpgpjs/openpgpjs#1363

Another option might be to add "type: "module" to package.json, and then use a dynamic import, but I'm not sure what else that will affect.

@bennettp123
Copy link
Author

bennettp123 commented Feb 6, 2023

Edit: removed, inaccurate

@larabr
Copy link
Collaborator

larabr commented Feb 6, 2023

Hi, this is related to #12 , and it's generally dependant on your TS configuration & build system. We're considering adding type: "module" to package.json, feel free to open a PR so that we can test the compatibility.

@larabr larabr closed this as completed Feb 6, 2023
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

2 participants