NftEyez/sol-rayz

it seems that an import is missing in utils.ts

Closed this issue · 13 comments

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';

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.

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

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

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

@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)

@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)

@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.

@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

Cool! Happy to help 🙂

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.

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

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

Stale issue message