question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sample script from Getting Started fails with Unexpected token import

See original GitHub issue

The sample script in the Getting Started section of the readme is failing with Unexpected token import error. It seems the reason is that node 8 didn’t have import. OS is Ubuntu 20.04.

> node -v
v8.11.4
SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
MaurGicommented, Aug 19, 2021

Same issue here:

You’re using Node 8 in 2021. I think that might be your problem.

That’s what the readme says: use version 8.11!

If I switch to the latest version of node/npm then I get an error installing the library. What version should we use?

$ node -v
v16.7.0
$ npm -v
7.20.3
$ nvm list
->      v16.7.0
default -> node (-> v16.7.0)
$ npm install web3
npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated multibase@0.7.0: This module has been superseded by the multiformats module
npm WARN deprecated multibase@0.6.1: This module has been superseded by the multiformats module
npm WARN deprecated multicodec@0.5.7: stable api reached

added 365 packages, and audited 366 packages in 25s

53 packages are looking for funding
  run `npm fund` for details

1 low severity vulnerability

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
$ npm list
maurgi@ /home/maurgi
└── web3@1.5.2
$ npm install opensea-js
npm WARN deprecated safe-event-emitter@1.0.1: Renamed to @metamask/safe-event-emitter
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated ethereumjs-block@2.2.2: New package name format for new versions: @ethereumjs/block. Please update.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated uuid@3.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated ethereumjs-tx@2.1.2: New package name format for new versions: @ethereumjs/tx. Please update.
npm WARN deprecated ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
npm WARN deprecated bignumber.js@6.0.0: Custom ALPHABET bug fixed in v7.0.2
npm WARN deprecated ethereumjs-vm@2.6.0: New package name format for new versions: @ethereumjs/vm. Please update.
npm WARN deprecated axios@0.17.1: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
npm WARN deprecated ethereumjs-block@1.7.1: New package name format for new versions: @ethereumjs/block. Please update.
npm WARN deprecated ethereumjs-common@1.5.2: New package name format for new versions: @ethereumjs/common. Please update.
npm WARN deprecated core-js@1.2.7: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /home/maurgi/.nvm/versions/node/v16.7.0/bin/node /home/maurgi/.nvm/versions/node/v16.7.0/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/maurgi/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN deprecated safe-event-emitter@1.0.1: Renamed to @metamask/safe-event-emitter
npm ERR! npm WARN deprecated har-validator@5.1.3: this library is no longer supported
npm ERR! npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm ERR! npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm ERR! npm WARN deprecated ethereumjs-block@2.2.0: New package name format for new versions: @ethereumjs/block. Please update.
npm ERR! npm WARN deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm ERR! npm WARN deprecated chokidar@2.1.6: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm ERR! npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm ERR! npm WARN deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info.
npm ERR! npm WARN deprecated uuid@3.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm ERR! npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm ERR! npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm ERR! npm WARN deprecated request@2.88.0: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! npm WARN deprecated ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
npm ERR! npm WARN deprecated bignumber.js@6.0.0: Custom ALPHABET bug fixed in v7.0.2
npm ERR! npm WARN deprecated ethereumjs-vm@2.6.0: New package name format for new versions: @ethereumjs/vm. Please update.
npm ERR! npm WARN deprecated buffer@4.9.1: This version of 'buffer' is out-of-date. You must update to v4.9.2 or newer
npm ERR! npm WARN deprecated axios@0.17.1: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
npm ERR! npm WARN deprecated ethereumjs-block@1.7.1: New package name format for new versions: @ethereumjs/block. Please update.
npm ERR! npm WARN deprecated ethereumjs-common@1.3.1: New package name format for new versions: @ethereumjs/common. Please update.
npm ERR! npm WARN deprecated core-js@2.6.9: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /home/maurgi/.npm/_cacache/tmp/git-clone-1c7fa961/node_modules/sha3
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c node-gyp rebuild
npm ERR! npm ERR! make: Entering directory '/home/maurgi/.npm/_cacache/tmp/git-clone-1c7fa961/node_modules/sha3/build'
npm ERR! npm ERR!   CXX(target) Release/obj.target/sha3/src/addon.o
npm ERR! npm ERR! make: Leaving directory '/home/maurgi/.npm/_cacache/tmp/git-clone-1c7fa961/node_modules/sha3/build'
npm ERR! npm ERR! gyp info it worked if it ends with ok
npm ERR! npm ERR! gyp info using node-gyp@7.1.2
npm ERR! npm ERR! gyp info using node@16.7.0 | linux | x64
npm ERR! npm ERR! gyp info find Python using Python version 3.8.5 found at "/usr/bin/python3"
npm ERR! npm ERR! (node:4736) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! npm ERR! gyp info spawn /usr/bin/python3
npm ERR! npm ERR! gyp info spawn args [
npm ERR! npm ERR! gyp info spawn args   '/home/maurgi/.nvm/versions/node/v16.7.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! npm ERR! gyp info spawn args   '-f',
npm ERR! npm ERR! gyp info spawn args   'make',
npm ERR! npm ERR! gyp info spawn args   '-I',
npm ERR! npm ERR! gyp info spawn args   '/home/maurgi/.npm/_cacache/tmp/git-clone-1c7fa961/node_modules/sha3/build/config.gypi',
npm ERR! npm ERR! gyp info spawn args   '-I',
npm ERR! npm ERR! gyp info spawn args   '/home/maurgi/.nvm/versions/node/v16.7.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! npm ERR! gyp info spawn args   '-I',
npm ERR! npm ERR! gyp info spawn args   '/home/maurgi/.cache/node-gyp/16.7.0/include/node/common.gypi',
npm ERR! npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! npm ERR! gyp info spawn args   '-Dnode_root_dir=/home/maurgi/.cache/node-gyp/16.7.0',
npm ERR! npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/home/maurgi/.nvm/versions/node/v16.7.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! npm ERR! gyp info spawn args   '-Dnode_lib_file=/home/maurgi/.cache/node-gyp/16.7.0/<(target_arch)/node.lib',
npm ERR! npm ERR! gyp info spawn args   '-Dmodule_root_dir=/home/maurgi/.npm/_cacache/tmp/git-clone-1c7fa961/node_modules/sha3',
npm ERR! npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! npm ERR! gyp info spawn args   '--depth=.',
npm ERR! npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! npm ERR! gyp info spawn args   '--generator-output',
npm ERR! npm ERR! gyp info spawn args   'build',
npm ERR! npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! npm ERR! gyp info spawn args ]
npm ERR! npm ERR! gyp info spawn make
npm ERR! npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! npm ERR! In file included from ../src/addon.cpp:4:
npm ERR! npm ERR! ../node_modules/nan/nan.h: In function ‘void Nan::AsyncQueueWorker(Nan::AsyncWorker*)’:
npm ERR! npm ERR! ../node_modules/nan/nan.h:2232:62: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
npm ERR! npm ERR!  2232 |     , reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
npm ERR! npm ERR!       |                                                              ^
npm ERR! npm ERR! ../src/addon.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE SHA3Hash::New(Nan::NAN_METHOD_ARGS_TYPE)’:
npm ERR! npm ERR! ../src/addon.cpp:49:23: warning: ‘new’ of type ‘SHA3Hash’ with extended alignment 32 [-Waligned-new=]
npm ERR! npm ERR!    49 |    obj = new SHA3Hash();
npm ERR! npm ERR!       |                       ^
npm ERR! npm ERR! ../src/addon.cpp:49:23: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
npm ERR! npm ERR! ../src/addon.cpp:49:23: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
npm ERR! npm ERR! ../src/addon.cpp: In static member function ‘static void SHA3Hash::Init(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’:
npm ERR! npm ERR! ../src/addon.cpp:69:52: warning: ‘v8::Local<v8::Context> v8::Object::CreationContext()’ is deprecated: Use MaybeLocal<Context> GetCreationContext() [-Wdeprecated-declarations]
npm ERR! npm ERR!    69 |   Local<Context> context = target->CreationContext();
npm ERR! npm ERR!       |                                                    ^
npm ERR! npm ERR! In file included from /home/maurgi/.cache/node-gyp/16.7.0/include/node/node.h:63,
npm ERR! npm ERR!                  from ../src/addon.cpp:1:
npm ERR! npm ERR! /home/maurgi/.cache/node-gyp/16.7.0/include/node/v8.h:4302:18: note: declared here
npm ERR! npm ERR!  4302 |   Local<Context> CreationContext();
npm ERR! npm ERR!       |                  ^~~~~~~~~~~~~~~
npm ERR! npm ERR! ../src/addon.cpp:83:27: error: no matching function for call to ‘v8::Object::Set(v8::Local<v8::String>&, v8::Local<v8::Function>&)’
npm ERR! npm ERR!    83 |   target->Set(className, f);
npm ERR! npm ERR!       |                           ^
npm ERR! npm ERR! In file included from /home/maurgi/.cache/node-gyp/16.7.0/include/node/node.h:63,
npm ERR! npm ERR!                  from ../src/addon.cpp:1:
npm ERR! npm ERR! /home/maurgi/.cache/node-gyp/16.7.0/include/node/v8.h:3948:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)’
npm ERR! npm ERR!  3948 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
npm ERR! npm ERR!       |                                     ^~~
npm ERR! npm ERR! /home/maurgi/.cache/node-gyp/16.7.0/include/node/v8.h:3948:37: note:   candidate expects 3 arguments, 2 provided
npm ERR! npm ERR! /home/maurgi/.cache/node-gyp/16.7.0/include/node/v8.h:3951:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)’
npm ERR! npm ERR!  3951 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
npm ERR! npm ERR!       |                                     ^~~
npm ERR! npm ERR! /home/maurgi/.cache/node-gyp/16.7.0/include/node/v8.h:3951:37: note:   candidate expects 3 arguments, 2 provided
npm ERR! npm ERR! In file included from ../src/addon.cpp:1:
npm ERR! npm ERR! ../src/addon.cpp: At global scope:
npm ERR! npm ERR! /home/maurgi/.cache/node-gyp/16.7.0/include/node/node.h:806:43: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]
npm ERR! npm ERR!   806 |       (node::addon_register_func) (regfunc),                          \
npm ERR! npm ERR!       |                                           ^
npm ERR! npm ERR! /home/maurgi/.cache/node-gyp/16.7.0/include/node/node.h:840:3: note: in expansion of macro ‘NODE_MODULE_X’
npm ERR! npm ERR!   840 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
npm ERR! npm ERR!       |   ^~~~~~~~~~~~~
npm ERR! npm ERR! ../src/addon.cpp:164:1: note: in expansion of macro ‘NODE_MODULE’
npm ERR! npm ERR!   164 | NODE_MODULE(sha3, SHA3Hash::Init)
npm ERR! npm ERR!       | ^~~~~~~~~~~
npm ERR! npm ERR! make: *** [sha3.target.mk:117: Release/obj.target/sha3/src/addon.o] Error 1
npm ERR! npm ERR! gyp ERR! build error 
npm ERR! npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.onExit (/home/maurgi/.nvm/versions/node/v16.7.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! npm ERR! gyp ERR! System Linux 5.10.16.3-microsoft-standard-WSL2
npm ERR! npm ERR! gyp ERR! command "/home/maurgi/.nvm/versions/node/v16.7.0/bin/node" "/home/maurgi/.nvm/versions/node/v16.7.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! npm ERR! gyp ERR! cwd /home/maurgi/.npm/_cacache/tmp/git-clone-1c7fa961/node_modules/sha3
npm ERR! npm ERR! gyp ERR! node -v v16.7.0
npm ERR! npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! npm ERR! gyp ERR! not ok
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/maurgi/.npm/_logs/2021-08-19T04_18_47_195Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/maurgi/.npm/_logs/2021-08-19T04_18_48_592Z-debug.log
0reactions
esteban-OpenSeacommented, Apr 19, 2022

Please use the latest version of Node and the SDK. If that doesn’t work try installing with yarn.

npm install --global yarn
yarn add opensea-js

Please follow this issue for the latest updates on the npm install: https://github.com/ProjectOpenSea/opensea-js/issues/471

I will close this out to avoid duplicates and confusion!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - SyntaxError: Unexpected token import - Stack Overflow
mjs file cannot import a file that uses require or module.exports . This was a huge problem, whereas esm allows you to mix...
Read more >
JavaScript ES6 - How to fix Unexpected token import - YouTube
This video is a short explanation on how to fix the syntax error : " Unexpected Token Import "Hint: type="module"
Read more >
Can't get simple script to run due to SyntaxError: Unexpected ...
Following the webpack documentation on the subject seems to give a Unexpected token import error. See webpack/webpack#5053 for more info. 1
Read more >
Unexpected Token Export: A Comprehensive Guide
The “unexpected token export” error occurs because the module is not compatible with the program. There are various reasons this happens. Fix it...
Read more >
How I Fixed The Unexpected Token Error In Jest
I have a CRA TS app and was getting import error for axios while testing. I updated the test script to react-scripts test...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found