Skip to content
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

Exception in require-from-string on Webpack: Can't resolve 'module' #576

Closed
ihorbond opened this issue Dec 20, 2021 · 4 comments · Fixed by #577
Closed

Exception in require-from-string on Webpack: Can't resolve 'module' #576

ihorbond opened this issue Dec 20, 2021 · 4 comments · Fixed by #577
Assignees
Labels

Comments

@ihorbond
Copy link

ihorbond commented Dec 20, 2021

Using solc installed via npm or by including a js script with nuxtjs

import * as wrapper from 'solc/wrapper';
const solc = wrapper(window.Module);

throws the following error

Module not found: Error: Can't resolve 'module' in 'C:\Code\NFTCalendar\NextFlip\node_modules\require-from-string'

apparently, this has been reported on the require-from-string repo
floatdrop/require-from-string#18

downgrading to require-from-string@1.2.1 does seem to fix the issue

but then it will throw

TypeError: Cannot use 'in' operator to search for '_solidity_version' in undefined
    at setupMethods (wrapper.js?92a3:10)
    at eval (index.vue?6ced:14)
    at Module../node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./pages/index.vue?vue&type=script&lang=js& (index.js:11)
    at __webpack_require__ (runtime.js:854)
    at fn (runtime.js:151)
    at eval (index.vue?ff57:1)
    at Module../pages/index.vue?vue&type=script&lang=js& (index.js:47)
    at __webpack_require__ (runtime.js:854)
    at fn (runtime.js:151)
    at eval (index.vue?b7d3:1)
    ```
@zyzhangyu
Copy link

I'm having the same problem as you and I haven't solved it, I think it's probably because I'm not familiar with the webpack settings, because many people don't report this error, my "require-from-string":"^2.0.2" is the latest version.

index.js:3 Uncaught Error: Cannot find module 'module'
    at webpackMissingModule (index.js:3)
    at Object../node_modules/require-from-string/index.js (index.js:3)
    at __webpack_require__ (bootstrap:24)
    at fn (hot module replacement:61)
    at Object../node_modules/solc/wrapper.js (wrapper.js:3)
    at __webpack_require__ (bootstrap:24)
    at fn (hot module replacement:61)
    at Module../src/page/deploy/index.js (index.js:18)
    at __webpack_require__ (bootstrap:24)
    at fn (hot module replacement:61)
webpackMissingModule @ index.js:3
./node_modules/require-from-string/index.js @ index.js:3
__webpack_require__ @ bootstrap:24
fn @ hot module replacement:61
./node_modules/solc/wrapper.js @ wrapper.js:3
__webpack_require__ @ bootstrap:24
fn @ hot module replacement:61
./src/page/deploy/index.js @ index.js:18
__webpack_require__ @ bootstrap:24
fn @ hot module replacement:61
./src/index.js @ immutable.js:19
__webpack_require__ @ bootstrap:24
(anonymous) @ startup:6
(anonymous) @ startup:6
index.js:548 [webpack-dev-server] Hot Module Replacement enabled.
index.js:548 [webpack-dev-server] Live Reloading enabled.
index.js:558 [webpack-dev-server] Errors while compiling. Reload prevented.
logger @ index.js:558
(anonymous) @ index.js:728
error @ index.js:177
errors @ index.js:168
(anonymous) @ socket.js:46
client.onmessage @ WebSocketClient.js:35
index.js:558 [webpack-dev-server] ERROR in ./node_modules/require-from-string/index.js 3:13-30
Module not found: Error: Can't resolve 'module' in '/Users/developer/Documents/GitHub/golddog/study/node_modules/require-from-string'

@cameel
Copy link
Member

cameel commented Dec 22, 2021

Here's a PR that should fix this by dropping require-from-string and reverting to the old method of loading module: #577.

Before we merge this though, we need to be really sure that it actually works and also that it does not break the module for people not using Webpack. It passes our current tests but so did the previous versions.

@cameel cameel changed the title Can't resolve 'module' Exception in require-from-string on Webpack: Can't resolve 'module' Dec 22, 2021
@ihorbond
Copy link
Author

ihorbond commented Dec 23, 2021

Thanks, I can try to import and use it like this in a no webpack environment if that helps with testing. Are there any specific scenarios?

@cameel
Copy link
Member

cameel commented Dec 23, 2021

Not really, we usually rely just on the tests in the repo. The change is very limited so I guess it might be enough to try it with webpack and then with some of the bigger non-webpack projects like Remix (in the browser) and Truffle/Hardhat (on node.js).

Honestly, I really don't have much confidence doing changes in this repo when they might affect compatibility with various JS runtime environments. Maybe we should have a CI run that installs some of these projects and runs their test suites. We're doing something similar in the main Solidity repo by running tests of some bigger Solidity-based projects. That would be a separate task though, not required to merge this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants