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

Error when using from react #64

Closed
jc064522 opened this issue Jul 3, 2017 · 3 comments
Closed

Error when using from react #64

jc064522 opened this issue Jul 3, 2017 · 3 comments

Comments

@jc064522
Copy link

jc064522 commented Jul 3, 2017

I see the error message Error: Cannot find module "." when trying to run a react app which includes node-zookeeper-client. The error occurs on line 776 when trying to require the specification file, ./specification.json. This file doesn't exist in the code bundled by webpack. I'm using node-zookeeper-client as a transitive dependency of zoologist.

A potential fix: if specification.json was specification.js and exported the json as a var then the import would work. I've tried this. Happy to put in a PR if you'd like me to. I could probably work around this with some webpack changes but: 1) at the moment the dependency fails when used from react and you probably don't want this and 2) I might have to 'eject' the app from the cradle of create-react-app and I'd rather not do that for this reason.

Steps to reproduce (I'm using yarn here but the steps could easily be npm):

  1. $ create-react-app node-zookeeper-client_react_test
    1. I'm using create-react-app version 1.3.1.
  2. $ cd node-zookeeper-client
  3. $ yarn add node-zookeeper-client
  4. Edit src/App.js and add var zookeeper = require('node-zookeeper-client'); below the imports. (Using an import produces the same error).
  5. $ yarn start and let it open the app's root page
@jlandersen
Copy link

Stumbled upon this as well - webpack in general doesen't like expression dependencies. Just changing:
var specification = require(SPECIFICATION_FILE);

to
var specification = require('specification.json');

seems to do the trick

@jc064522 jc064522 closed this as completed Jan 9, 2018
@snoodleboot
Copy link

Doesn't appear to me that this was ever resolved

@poojaKarande13
Copy link

@jlandersen the fix suggested by you worked!
On line 771 in node_modules/node-zookeeper-client/lib/jute/index.js I changed
var specification = require(SPECIFICATION_FILE);
to
var specification = require('./specification.json');

Background: I am trying to use npm kafka-node in a React web app. (kafka-node has an internal dependency on node-zookeeper-client.)
On running the command npm start I got this error Error: Cannot find module "./specification.json"

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

4 participants