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.

ES6 Module Consumption

See original GitHub issue

When attempting you use a modern bundler (in my case its Rollup http://rollupjs.org/). I cannot import individual modules that I need because they aren’t exported correctly.

Module MY_PROJECT/node_modules/web3-provider-engine/subproviders/rpc.js does not export default (imported by MY_PROJECT/lib/index.js)

Error: Module MY_PROJECT/node_modules/web3-provider-engine/subproviders/rpc.js does not export default (imported by MY_PROJECT/lib/index.js)

at Module.trace (MY_PROJECT/node_modules/rollup/src/Module.js:683:30)
at MY_PROJECT/node_modules/rollup/src/Module.js:265:30
at Array.forEach (native)
at MY_PROJECT/node_modules/rollup/src/Module.js:263:25
at Array.forEach (native)
at Module.bindReferences (MY_PROJECT/node_modules/rollup/src/Module.js:256:19)
at MY_PROJECT/node_modules/rollup/src/Bundle.js:104:44
at Array.forEach (native)
at MY_PROJECT/node_modules/rollup/src/Bundle.js:104:18

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
BennyMcommented, May 29, 2017

Ok got it to work using the following syntax in my code:

import * as Web3ProviderEngine  from 'web3-provider-engine';
import * as RpcSource  from 'web3-provider-engine/subproviders/rpc';
import * as HookedWalletSubprovider from 'web3-provider-engine/subproviders/hooked-wallet';
0reactions
BennyMcommented, May 28, 2017

I’m using Webpack instead of rollup and am also experiencing difficulties. After importing

import { Web3ProviderEngine } from 'web3-provider-engine';

and creating an object

var engine = new Web3ProviderEngine();

I get the error: Web3ProviderEngine is not a constructor function.

The generated javascript looks like this:

var engine = new web3_provider_engine_1.Web3ProviderEngine();

While poking around in the browser I can find the function at the prefix.

image

Not sure if this is a webpack issue or the way the library is structured. I don’t experience this issue with for instance web3 or eth-lightwallet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript modules - MDN Web Docs
Use of native JavaScript modules is dependent on the import and export statements; these are supported in browsers as shown in the compatibility ......
Read more >
A Practical guide to ES6 modules - freeCodeCamp
In short, we need ES6 modules in order to effectively reuse, maintain, separate and encapsulate internal behaviour from external behaviour. It's ...
Read more >
JavaScript modules via script tag | Can I use... Support tables ...
Loading JavaScript module scripts (aka ES6 modules) using <script type="module"> Includes support for the nomodule attribute. Usage % of.
Read more >
ES6 Modules and How to Use Import and Export in JavaScript
The ES2015 (ES6) edition of the JavaScript standard gives us native support for modules with the import and export syntax.
Read more >
ES6 module usage - CodeSandbox
ES6 module usage. 0. Embed Fork Create Sandbox Sign in. Sandbox Info. ES6 module usage. 0. 2.0k. 230. eugenechen0514eugenechen0514. Environmentcreate-react- ...
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