I can't import the web3 file there is an error ,SyntaxError: Cannot use import statement outside a module

I used npm, to install the web3 library

this error is in the phaser

2 Answers 2


Try using

const web3 = require("web3.js");

If you want to use the import statement you need to add a line in your package.json called "type": "module", learn more here.


This is more of a JS error in general. You can use const Web3 = require('web3'); to import.

//INDEX.JS file
const Web3 = require("web3"); //The keyword web3 is case sensative
const web3 = new Web3("RPC LINK"); //Connect to an RPC and start using web3

   ... //more code

Or you can edit package.json. You will need put "type": "module", at the root of your JSON file.

  "name": "index",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",

   ... //more

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.