Sparticuz / usps-webtools-promise

USPS Web Tools API wrapper
14 stars 4 forks source link

Error loading NPM module in Wix environment #21

Closed dbogan98 closed 1 year ago

dbogan98 commented 1 year ago

I am trying to use usps-webtools-promise through the NPM module functionality of Wix Velo. Unfortunately, the module does not load properly with the following console message. Any help appreciated.

Error: Error loading web module backend/verifyAddress.jsw: Must use import to load ES Module: /dynamic-modules/third-party-npm/3dc35ea1/WC_BEGIN/usps-webtools-promise/5.0.0/WC_END/usps-webtools-promise/dist/usps.js require() of ES modules is not supported. require() of /dynamic-modules/third-party-npm/3dc35ea1/WC_BEGIN/usps-webtools-promise/5.0.0/WC_END/usps-webtools-promise/dist/usps.js from backend/verifyAddress.jsw is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename usps.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /dynamic-modules/third-party-npm/3dc35ea1/WC_BEGIN/usps-webtools-promise/5.0.0/WC_END/usps-webtools-promise/package.json.

Sparticuz commented 1 year ago

You'll need to use import USPS from "usps-webtools-promise";. This package has dropped CJS support starting at v5. https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c