1Password / op-js

A JS library powered by the 1Password CLI
https://developer.1password.com/docs/cli
MIT License
91 stars 8 forks source link

SyntaxError: Named export 'item' not found. The requested module '@1password/op-js' is a CommonJS module, which may not support all module.exports as named exports. #153

Closed pro-sumer closed 1 year ago

pro-sumer commented 1 year ago

Your environment

op-js version: 0.1.10

CLI version: 2.19.0

OS: macOS Ventura 13.5.1

What happened?

Syntax error when importing op-js after upgrading from 0.1.9 to 0.1.10:

SyntaxError: Named export 'item' not found. The requested module '@1password/op-js' is a CommonJS module, which may not support all module.exports as named exports.

(import succeeds after reverting to 0.1.9)

What did you expect to happen?

Import succeeds as before (with 0.1.9).

Steps to reproduce

  1. Have this in package.json:
    {
    ...
    "dependencies": {
    "@1password/op-js": "0.1.10",
    ...
    },
    "type": "module",
    ...
    }
  2. Import item from op-js (and rename it):
    import { item as opItem } from '@1password/op-js'

Notes & Logs

ineffyble commented 1 year ago

I'm getting similar errors but from the other side - my codebase is CommonJS and I can't use 0.1.10 because I get an "Cannot use import statement outside a module" error, because dist/index.js contains import statements (e.g. ESM syntax).

jodyheavener commented 1 year ago

Hey all, yes thanks for raising this. We recently changed how the package was compiled so that we weren't bundling all the dependencies together. The package was previously all CJS but our change resulted in some ESM syntax being used. The fix I have moves us back to an all CJS package. I'll have up shortly.

ineffyble commented 1 year ago

A coworker linked me this today, it's very handy to know about: https://publint.dev/@1password/op-js@0.1.10

jodyheavener commented 1 year ago

Oh dang, that is very neat! Thank you for sharing :)