-
Notifications
You must be signed in to change notification settings - Fork 310
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
Property 'toCanvas' does not exist on type 'typeof BwipJs' #316
Comments
How do you expect me to help you when you have provided no details on your problem? Please read: https://freecodecamp.org/news/how-to-ask-a-question-on-a-forum/ |
I do apologize, let me try again: |
Since it looks like typescript is grabbing the wrong import, please try the following:
This is a to be documented feature, once more real world testing has been acquired.... |
Thanks for that but in that case it cannot find the module |
Are you using a modern version of the typescript compiler/bundler? It appears your version does not understand the |
This is an issue for me, as well, also using TypeScript/React. I'm using the latest version of the TypeScript compiler, 5.3.2 as of right now. I was able to clear the error and get the hover text working by messing with bwip-js package.json but I don't know what I'm doing there enough to provide a clean fix. TypeScript calls it an error but it works when run. Without using the suggested fix, with import statement:
the error is shown on toCanvas as:
When using:
the error is shown on the import:
Still works in both cases. |
Interesting that the code works. The actual issue is the compiler failing to find the types declaration. Looking more in depth at the typescript docs, this caught my eye:
I think we can leverage that behavior. In the file
And replace with:
In your code, use the qualified import:
|
Unfortunately, this didn't work for me, but I saw where you were going and tried messing with it for a while. I didn't find a clean solution, but what worked for me was to change:
to:
As a result, I realized I was instead able to import from a full path, i.e.
and it was properly recognized and worked. If I try to do:
I get an error:
and it doesn't work. It did lead me to this: evanw/esbuild#1484 but their solution also didn't work. It seems to be skipping the exports entirely. It may just be the way my project is configured. I realize that this isn't a fix for you, but maybe it's a clue. |
That pretty much proves the compiler is not using the exports map for module resolution. Possibly you have an out-of-date config file that is preventing the compiler from using it? Other than that, there is not much more I can do. The obsolete |
Hi, I've just installed version 4.2.0 of your package, for a react native project (expo v50 sdk). es imports are not importing the proper export for react native, and therefore toDataURL does not exist. I've attempted your previous suggestions as trying to import directly from |
@z1haze : Please post a zip of a minimal app that exhibits the behavior. Make sure it includes the configuration file(s) you are using. I will try to get this figured out. |
here you go |
we were able to get things "working" by adding our own path alias to the tsconfig for your package to resolve the correct type declarations: |
This was an interesting rabbit hole to go down. Not sure what the expo package is (not a react-native developer), but its
To debug this, I used the
So it was using the |
Alternatively, you can use the explicit
For both of these usages, you must be using at least |
Hey @metafloor, thanks for looking into this. Expo is just an SDK for react native. I guess you can consider it the nextjs for native apps. using react-native. That said, I applied your suggested fixes, and while it does make the compiler happy, and module resolution appears to function properly, the bundler still blows up because it cannot resolve the module (when referencing the import via Also, we use node 18, if that matters. Lastly, the bundler is metro, so if there's something that needs to happen with that too, please let us know. This though, if the first time I've ever had an issue with a package module resolution like this. When stuff like this happens I tend to lean more toward an issue with the package structure and not the other way around... e.g. if 19/20 are in a line, and one is out of line, who is wrong? |
The difference between bwip-js and other packages is that there are three separate platform targets: browser, node, and react-native. And actually four since there is a generic svg-only target as well. Most (almost all) packages either support a single generic javascript target or a single platform. The exports map is relatively new - node v12 was released in 2020 - and not enabled by a lot of bundlers. For example, here is metro's exports map documentation. It is not enabled by default. So for metro, you need to set Please use the alternate |
Alright, that works for me. Thank you for getting to the bottom of this! |
This issue is still not solved with 4.1.2
Currently using react 18.2.0
The text was updated successfully, but these errors were encountered: