Skip to content

Error: Cannot find module 'ws' #112

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

Open
steventen opened this issue Jun 26, 2015 · 12 comments
Open

Error: Cannot find module 'ws' #112

steventen opened this issue Jun 26, 2015 · 12 comments

Comments

@steventen
Copy link

Hi,
I'm using npm to install sql.js. But when watchify try to bundle the app up, it will throw this error:

 Error: Cannot find module 'ws' from 'C:\my_location\node_modules\sql.js\js'

And in the js file, I only have something like this:

var fs = require('fs');
var SQL = require('sql.js');

var filebuffer = fs.readFileSync('../../db/my_db.sqlite');
var _sqlConn = new SQL.Database(filebuffer);

I'm using a Windows 7 laptop

I really don't know how can i solve this, thanks

@lovasoa
Copy link
Member

lovasoa commented Jun 26, 2015

I don't think there is any reference anywhere in the code to the ws module. Are you sure this issue is related to sql.js?

@moimael
Copy link

moimael commented Jul 9, 2015

I also have the same issue, right after installing sql.js

I found a require('ws') in sql.js
It is minified but in sublime text i found it line 336

d=new (s?require("ws"):window.WebSocket)
Error("WebSocket URL must be in the format ws(s)://address:port"))

@moimael
Copy link

moimael commented Jul 9, 2015

Relevant issue : fabiosantoscode/require-emscripten#1

@nathanhere
Copy link

I'm having this issue as well.

@chauthai
Copy link

chauthai commented Sep 2, 2015

I'm using webpack to build my app and I've got the same:

ERROR in ./~/sql.js/js/sql.js
Module not found: Error: Cannot resolve module 'fs' in /Users/thai/Documents/CrossMIP/frame/node_modules/sql.js/js
 @ ./~/sql.js/js/sql.js 4:141-154 361:205-218

ERROR in ./~/sql.js/js/sql.js
Module not found: Error: Cannot resolve module 'ws' in /Users/thai/Documents/CrossMIP/frame/node_modules/sql.js/js
 @ ./~/sql.js/js/sql.js 337:113-126 342:44-57```

@chauthai
Copy link

chauthai commented Sep 3, 2015

I've fixed the problem by including the sql.js lib manually in my index.html and bypassing webpack or browserify build steps.
Works fine so far!

@screendriver
Copy link

Same here with SystemJS and jspm. See also jspm/jspm#1108

@lovasoa
Copy link
Member

lovasoa commented Sep 9, 2015

Ok, the problem with the tools you use is that they look at the code for uses of require() and try to include the dependencies. The tool with which sql.js is compiled (emscripten) generates conditional requires, that won't be used in the browser. So either file an issue to the tool you use to process your js for it to be more clever about requires, or to emscripten not to generate these requires. But anyway, I don't think there is something I can do in sql.js.

@lovasoa
Copy link
Member

lovasoa commented Sep 9, 2015

@kripken : Any idea about this?

@kripken
Copy link
Collaborator

kripken commented Sep 9, 2015

Emscripten generates those conditional requires so the same output can run in node and on the web (and elsewhere). We've discussed adding compile-time options to target only one platform, but no one has written a pull request yet.

@dougmartin
Copy link

dougmartin commented Mar 16, 2017

Here is another fix for the Error: Cannot resolve module 'fs' error reported by @chauthai - use an externals block in your webpack config to make webpack think the fs module is external like this:

    externals: [
        {fs: true}  // to get sql.js to load - emscripten uses the fs module in certain codepaths we don't use so fake its availability
    ],

@skysign
Copy link

skysign commented Oct 21, 2017

This is my way, to use webpack with sql.js

The line below is added in html file, It seems that we can't build sql.js by webpack.

<script src="https://unpkg.com/[email protected]/js/sql.js"></script>

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

No branches or pull requests

9 participants