Issue with import solana/web3.js package

558 views Asked by At

I have imported solana/web3.js package and it working fine when I am running node js file

import {
    Transaction,
    SystemProgram,
    Keypair,
    Connection,
    sendAndConfirmTransaction,
    clusterApiUrl
} from "@solana/web3.js"

But when I try to connect this file with basic HTML, it throws the error.

Uncaught TypeError: Failed to resolve module specifier "@solana/web3.js". Relative references must start with either "/", "./", or "../".

I also tried with Vue JS project, but it didn't help

Image error

1

There are 1 answers

0
Jon C On

You may be trying to use the file without a build system, in which case you should use the unpkg versions, ie:

<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.min.js"></script>

Documentation at https://www.npmjs.com/package/@solana/web3.js#for-use-in-a-browser-without-a-build-system