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

bug: fixed bug when trying to import module using node esm and added … #190

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ All exports are stored under `warp` global variable.
</script>
```

#### Using esm bundles

Bundle files are possible to use in esm web environment only. Use minified version for production. It is possible to use latest or specified version.

```html
<!-- Latest -->
<script src="https://unpkg.com/warp-contracts/bundles/esm.bundle.js"></script>

<!-- Latest, minified-->
<script src="https://unpkg.com/warp-contracts/bundles/esm.bundle.min.js"></script>

<!-- Specific version -->
<script src="https://unpkg.com/warp-contracts@1.0.0/bundles/esm.bundle.js"></script>

<!-- Specific version, minified -->
<script src="https://unpkg.com/warp-contracts@1.0.0/bundles/esm.bundle.min.js"></script>
```

### Using the Warp Gateway

#### SDK version >= `0.5.0`
Expand Down
10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"./esm": "bundles/esm.bundle.js",
"./web": "bundles/web.bundle.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this not break the #152 (comment) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reference the bundled web and esm you would use

import { WarpWebFactory } from 'warp-contracts/bundles/esm.bundle'

instead of

import { WarpWebFactory } from 'warp-contracts/esm'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I continue to struggle with this issue, but I have narrowed down the root cause. The ./lib/esm/index.js build is not esm compliant, I don't know why it is not, but I do know when I switch the exports config to point the import to cjs it works fine.

"exports": {
    ".": {
      "import": "./lib/cjs/index.js",
      "require": "./lib/cjs/index.js"
    },
    "./esm": "bundles/esm.bundle.js",
    "./web": "bundles/web.bundle.js"
  },

So that may be another option.

The current esm build results in this response:

file:///workspace/stamp-coin/copy-and-deploy.mjs:4
import { WarpFactory } from './warp/lib/esm/index.js'
         ^^^^^^^^^^^
SyntaxError: Named export 'WarpFactory' not found. The requested module './warp/lib/esm/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from './warp/lib/esm/index.js';
const { WarpFactory } = pkg;

For now, I am just pulling down the latest source and patching the package.json

npx degit warp-contracts/warp#v1.2.0-rc.1 warp
cd warp
npx json -I -f package.json -e 'this.exports.import = "./lib/cjs/index.js"'
yarn && yarn build:cjs

Please, let me know how I can help move this bug to fixed.

},
"sideEffects": false,
"engines": {
"node": ">=16.5"
Expand Down Expand Up @@ -118,4 +110,4 @@
"stream-buffers": false,
"constants": false
}
}
}