-
Notifications
You must be signed in to change notification settings - Fork 249
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
Can't import from near-api-js
in vite/vue applicaiton
#1072
Comments
Thank you for taking the time to open an issue @SeriousLeeTV! This has been a longstanding issue and point of frustration for many developers, see the nearly two-year-old #607 😕 However recently I had the chance to refactor Please don't hesitate to leave any feedback on these PRs, community input on these would certainly help in making this issue more visible 🙂. In particular #1067 adds an example-vite package as an example of how usage will look in this context going forward. |
Hi @andy-haynes ! Thanks for getting back to me and apologies for my delayed response. Okay cool, I'm just trying to wrap my head around it. So are you saying there's no way to get the Or what changes can I make to my project to get it working? I'm open to anything at this point as we're in a time crunch and I have to deliver a feature that uses this package ASAP 😅 |
@SeriousLeeTV I just meant to convey that with Vite in particular there are compatibility issues exacerbating things, but the situation is on track to improve 🙂 Looking at comments on that issue I linked above, I see that another dev was able to sort it out nearly a year ago: #607 (comment) I see some other workarounds in that thread that seem relevant as well, it's probably worth giving those a shot.
From searching the error message you posted it seems likely the issue is with |
@SeriousLeeTV , @andy-haynes this is a pretty common issue with Vite and other modern bundlers also with webpack 5, buffer does not get added/imported by default (or gets ignored) so you will need to provide it as a polyfill. Here's working demo of Live demo: https://kujtimprenkusqa.github.io/near-api-js-vue/ Check the commit history to understand it better, there's a fix for a production error too reported here: #1035 . UPDATE: If you don't prefer the way I added polyfills for |
Thanks for the massive assist @andy-haynes and @kujtimprenkuSQA! I tried @kujtimprenkuSQA's first link and it's working for me, so I'm going to carry on with that for now. Cheers! |
@LeeGrobler The issue is fixed now as large near-api-js was broken down into multiple number of smaller packages as (@near-js/*) . You can find the packages at https://www.npmjs.com/search?q=%40near-js and use es6 imports as:
|
Prerequisites
near-api-js
.Description
Importing anything from
near-api-js
results inUncaught TypeError: Cannot read properties of undefined (reading 'from')
Reproducible demo
No response
Steps to reproduce
npm create vite@latest
vite-and-vue-app
,Vue
,JavaScript
cd vite-and-vue-app
npm i
npm run dev
then navigate to the localhost url produced in the terminalnear-api-js
:npm i near-api-js
keyStores
(or anything else) fromnear-api-js
:import { keyStores } from 'near-api-js'
Expected behavior
It shouldn't throw an error and should allow me to import the modules that I need.
Actual behavior
It produces the error mentioned in the Description.
Your environment
near-api-js: ^1.1.0
vue: ^3.2.45
vite: ^4.1.0
Self-service
The text was updated successfully, but these errors were encountered: