Closed jamescrowley closed 2 years ago
Hi @jamescrowley - thanks for the information. I have been able to reproduce the issue you are seeing.
It looks that the esbuild
bundler is incorrectly bundling in the example provided.
As you are bundling your code with esbuild
the easiest way to fix this in this case is to change the import of the @what3words/api
library to
import * as what3words from '@what3words/api/es2015';
@c5haw I haven't been able to get that to work. I get
"navigator is not defined",
in lambda, along with errors highlighting the use of 'fetch' and navigator, as I guess those are browser-only and not for a node environment?
@c5haw having looked at your build process further, I guess we need the es2015 build, but without the browser targeting and the swapping in of the fetch.browser.ts. Would you be open to this being added? (happy to submit a PR). I guess it would have to be an additional distribution to avoid breaking compatibility at this stage, but all ears if you can think of a nicer solution, not sure how other libraries handle this
@c5haw see also the comment here: https://github.com/evanw/esbuild/issues/1753#issuecomment-963796880 - it seems like the recommendation in the Typescript docs for node distributions is to use commonJS rather than umd
Hi @jamescrowley - thanks for the information. I am working for a fix on this and should be finished soon. Apologies for the delay in getting back to you.
@jamescrowley we've released a new version of the library that should resolve these issues you've had. Please check the updated documentation for the latest changes.
Raising a separate issue to https://github.com/what3words/w3w-node-wrapper/issues/29 specifically for the second error
Cannot find module './constants'
mentioned there, as I'm reproducing currently in a similar set up (AWS lambda using CDK, which uses esbuild under the hood in their NodeJsFunction abstraction). This appears to be either an issue with your library, or with esbuild. I have raised an issue over there too, but logging here in case you have suggestions.This is the simplified command that generates the transpiled-JS which triggers the 'cannot find module' error.
esbuild --bundle "index.ts" --platform=node
index.ts:
tsconfig.json:
package.json:
and the error:
Runtime.ImportModuleError: Error: Cannot find module './constants'
I also experimented with importing @what3words/api/umd as suggested in the other ticket but that made no difference to the JS transpilation output.