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 casual with create-react-app #86

Open
dplaton opened this issue Mar 20, 2019 · 4 comments
Open

Error when using casual with create-react-app #86

dplaton opened this issue Mar 20, 2019 · 4 comments

Comments

@dplaton
Copy link

dplaton commented Mar 20, 2019

Steps to reproduce:

  1. Create a new React app using create-react-app, i.e. npm create react-app casual-test
  2. Run yarn add casual
  3. Update the default App.js component like this
  4. Run yarn start

The browser opens automatically and shows an error page saying TypeError: exists is not a function, pointing to this line

Tested on macOs Mojave (10.14.3) and Windows 10 1803

A quick SO search revealed this similar issue (Webpack...).

@liquidvisual
Copy link

liquidvisual commented Mar 22, 2019

Happened to me too with Vue.js, I think this library is not for Webpack - but for Node.js.

I ended up using https://github.com/marak/Faker.js/ which worked fine.

@dplaton
Copy link
Author

dplaton commented Mar 23, 2019

@liquidvisual Sadly, I didn't manage to fix this. It appears to be an issue with Webpack - I could reproduce it even with a simple Webpack config an a code similar to

const fs = require('fs');
if (!fs) {
    console.log('No FS!');
}

When I executed the script without Webpack (i.e. using node) it ran successfully. When I bundled it with Webpack and ran it on a wepbage I hit the No FS! message.

@likethemammal
Copy link

I fixed this issue by using casual-browserify. Didnt need to change my webpack config at all, but I did need to replace the imports in any of the files that webpack built for the browser.

import casual from 'casual'

// to

import casual from 'casual-browserify'

liqueurdetoile added a commit to liqueurdetoile/casual that referenced this issue May 9, 2019
It produces an UMD module that can be used in browser and Node

fix boo1ean#86
@fiznool
Copy link

fiznool commented Dec 12, 2019

If you are running causal in the browser then you will need to tell webpack to bundle the fs module with your code. fs is something that only (by default) exists when running the code on the server with node.

Take a look at the node webpack configuration for instructions on how to bundle node APIs for consumption in the browser.

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