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

it seems that an import is missing in utils.ts #16

Closed
QuentinL-hub opened this issue Feb 4, 2022 · 13 comments
Closed

it seems that an import is missing in utils.ts #16

QuentinL-hub opened this issue Feb 4, 2022 · 13 comments
Assignees

Comments

@QuentinL-hub
Copy link

QuentinL-hub commented Feb 4, 2022

Buffer is not declared

https://github.com/NftEyez/sol-rayz/blob/main/packages/sol-rayz/src/utils.ts

npm i buffer

then :

import { Buffer } from 'buffer';

@jamland jamland self-assigned this Feb 5, 2022
@jamland
Copy link
Member

jamland commented Feb 5, 2022

hey Quentin!

Do you have any error/warning about it in your editor or browser?
I believe TS uses this type in such case:
https://microsoft.github.io/PowerBI-JavaScript/classes/_node_modules__types_node_globals_d_.buffer.html

I don't think you need to install/use this package, because is not assumed to be used here.

@QuentinL-hub
Copy link
Author

Yeah actually i had to import this package i had this error :

Uncaught (in promise): ReferenceError: assignment to undeclared variable Buffer

In my angular project

@jamland
Copy link
Member

jamland commented Feb 7, 2022

I see, then probably quick fix will be to install node.js types like this:

npm install --save @types/node

I will look into the package and will fix as well

@bayo-net
Copy link

bayo-net commented Feb 7, 2022

Same issue with utils.js for me.
Here is the error message.
ModuleNotFoundError
Could not find module in path: 'assert/assert.js' relative to '/node_modules/@solana/spl-name-service/dist/utils.js'
https://codesandbox.io/s/awesome-smoke-3rmpj?file=/src/App.js
I've tried installing assert.js. Didn't work for me, Any idea for a quick fix here? Thanks

@dino-rodriguez
Copy link

@jamland It looks the types fix doesn't work, because the error is coming from the javascript files. Here is the error in my console:

Uncaught ReferenceError: Buffer is not defined
at Object../node_modules/@nfteyez/sol-rayz/dist/utils.js (utils.ts:21:1)
at Object.options.factory (react refresh:6:1)
at webpack_require (bootstrap:24:1)
at fn (hot module replacement:61:1)
at Object../node_modules/@nfteyez/sol-rayz/dist/getParsedNftAccountsByOwner.js (getParsedNftAccountsByOwner.ts:4:1)
at Object.options.factory (react refresh:6:1)
at webpack_require (bootstrap:24:1)
at fn (hot module replacement:61:1)
at Object../node_modules/@nfteyez/sol-rayz/dist/index.js (index.ts:1:1)
at Object.options.factory (react refresh:6:1)

@jamland
Copy link
Member

jamland commented Feb 8, 2022

@dino-rodriguez thank you for the note. I suppose your and other webpack might have different config, so it doesn't include Buffer. As a fix, I have replaced Buffer with TextEncoder.

Please update packages to the latest version and try again (0.10.0)

@jamland
Copy link
Member

jamland commented Feb 8, 2022

@bayo-net looks like you have a different issue. Hard to say, but for sure you don't need to install assert. The package doesn't use it. looks weird..

But try to update the package anyway.

@dino-rodriguez
Copy link

@jamland That was totally it. I was using a workaround by adding a webpack plugin to buffer, but this is better. Thank you! It works

@jamland
Copy link
Member

jamland commented Feb 8, 2022

Cool! Happy to help 🙂

@burkarddev
Copy link

I am still having same issue on 0.10.2 @jamland. I think it's webpack problem on @solana/spl-name-service package. It uses webpack v3 but my project uses v5.

@mohit000001
Copy link

@burkarddev , Same issue with me. @jamland Please provide solution.

@jamland
Copy link
Member

jamland commented Feb 22, 2022

the issue occurs because webpack 5 doesn't provide Buffer and other Node.js global objects by default now.
I've updated our code respectively but we use 3rd party packages @solana/spl-name-service which still uses Buffer. I will check if solana team going to update this package or if I can commit to it.

So far, the simplest solution will be not to use webpack 5.
Read similar issue here --->
anza-xyz/wallet-adapter#241.

Additionally, here is boilerplate Next.js / React.JS template I use myself, which work well with this package and other solana tools
https://github.com/thuglabs/create-dapp-solana-nextjs

@github-actions
Copy link

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants