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

Mis-leading documentation #847

Closed
joetidee opened this issue Mar 13, 2017 · 10 comments
Closed

Mis-leading documentation #847

joetidee opened this issue Mar 13, 2017 · 10 comments

Comments

@joetidee
Copy link

I am using Webpack 2 and React 15.x in my application. Your documentation gives two different configurations for externals:

https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md

So which one do i use?

@ljharb
Copy link
Member

ljharb commented Mar 13, 2017

It looks like you want to use the "webpack 2" one, but omit the "cheerio" line.

If that works, then a PR to update the readme would be very appreciated :-)

@joetidee
Copy link
Author

joetidee commented Mar 13, 2017

Having problems with this setting. Getting the following errors on this repo (when running npm test):

https://github.com/joetidee/erl-example

Errors:

ERROR in ./~/enzyme/build/react-compat.js
Module not found: Error: Can't resolve 'react/addons' in '/mnt/c/ubuntu/erl-example/node_modules/enzyme/build'
resolve 'react/addons' in '/mnt/c/ubuntu/erl-example/node_modules/enzyme/build'
  Parsed request is a module
  using description file: /mnt/c/ubuntu/erl-example/node_modules/enzyme/package.json (relative path: ./build)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /mnt/c/ubuntu/erl-example/node_modules/enzyme/package.json (relative path: ./build)
    resolve as module
      /mnt/c/ubuntu/erl-example/node_modules/enzyme/build/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/erl-example/node_modules/enzyme/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/erl-example/node_modules/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/node_modules doesn't exist or is not a directory
      /mnt/c/node_modules doesn't exist or is not a directory
      /mnt/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /mnt/c/ubuntu/erl-example/node_modules
        using description file: /mnt/c/ubuntu/erl-example/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: /mnt/c/ubuntu/erl-example/package.json (relative path: ./node_modules)
          using description file: /mnt/c/ubuntu/erl-example/node_modules/react/package.json (relative path: ./addons)
            as directory
              /mnt/c/ubuntu/erl-example/node_modules/react/addons doesn't exist
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/addons doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/addons.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/addons.json doesn't exist
[/mnt/c/ubuntu/erl-example/node_modules/enzyme/build/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/enzyme/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/node_modules]
[/mnt/c/ubuntu/node_modules]
[/mnt/c/node_modules]
[/mnt/node_modules]
[/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/react/addons]
[/mnt/c/ubuntu/erl-example/node_modules/react/addons]
[/mnt/c/ubuntu/erl-example/node_modules/react/addons.js]
[/mnt/c/ubuntu/erl-example/node_modules/react/addons.json]
 @ ./~/enzyme/build/react-compat.js 41:16-39 42:46-69
 @ ./~/enzyme/build/ShallowWrapper.js
 @ ./~/enzyme/build/index.js
 @ ./test.js

ERROR in ./~/enzyme/build/react-compat.js
Module not found: Error: Can't resolve 'react/lib/ReactContext' in '/mnt/c/ubuntu/erl-example/node_modules/enzyme/build'
resolve 'react/lib/ReactContext' in '/mnt/c/ubuntu/erl-example/node_modules/enzyme/build'
  Parsed request is a module
  using description file: /mnt/c/ubuntu/erl-example/node_modules/enzyme/package.json (relative path: ./build)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /mnt/c/ubuntu/erl-example/node_modules/enzyme/package.json (relative path: ./build)
    resolve as module
      /mnt/c/ubuntu/erl-example/node_modules/enzyme/build/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/erl-example/node_modules/enzyme/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/erl-example/node_modules/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/node_modules doesn't exist or is not a directory
      /mnt/c/node_modules doesn't exist or is not a directory
      /mnt/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /mnt/c/ubuntu/erl-example/node_modules
        using description file: /mnt/c/ubuntu/erl-example/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: /mnt/c/ubuntu/erl-example/package.json (relative path: ./node_modules)
          using description file: /mnt/c/ubuntu/erl-example/node_modules/react/package.json (relative path: ./lib/ReactContext)
            as directory
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext doesn't exist
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext.json doesn't exist
[/mnt/c/ubuntu/erl-example/node_modules/enzyme/build/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/enzyme/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/node_modules]
[/mnt/c/ubuntu/node_modules]
[/mnt/c/node_modules]
[/mnt/node_modules]
[/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext.js]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ReactContext.json]
 @ ./~/enzyme/build/react-compat.js 43:23-56
 @ ./~/enzyme/build/ShallowWrapper.js
 @ ./~/enzyme/build/index.js
 @ ./test.js

ERROR in ./~/enzyme/build/react-compat.js
Module not found: Error: Can't resolve 'react/lib/ExecutionEnvironment' in '/mnt/c/ubuntu/erl-example/node_modules/enzyme/build'
resolve 'react/lib/ExecutionEnvironment' in '/mnt/c/ubuntu/erl-example/node_modules/enzyme/build'
  Parsed request is a module
  using description file: /mnt/c/ubuntu/erl-example/node_modules/enzyme/package.json (relative path: ./build)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /mnt/c/ubuntu/erl-example/node_modules/enzyme/package.json (relative path: ./build)
    resolve as module
      /mnt/c/ubuntu/erl-example/node_modules/enzyme/build/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/erl-example/node_modules/enzyme/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/erl-example/node_modules/node_modules doesn't exist or is not a directory
      /mnt/c/ubuntu/node_modules doesn't exist or is not a directory
      /mnt/c/node_modules doesn't exist or is not a directory
      /mnt/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /mnt/c/ubuntu/erl-example/node_modules
        using description file: /mnt/c/ubuntu/erl-example/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: /mnt/c/ubuntu/erl-example/package.json (relative path: ./node_modules)
          using description file: /mnt/c/ubuntu/erl-example/node_modules/react/package.json (relative path: ./lib/ExecutionEnvironment)
            as directory
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment doesn't exist
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment.json doesn't exist
[/mnt/c/ubuntu/erl-example/node_modules/enzyme/build/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/enzyme/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/node_modules]
[/mnt/c/ubuntu/node_modules]
[/mnt/c/node_modules]
[/mnt/node_modules]
[/node_modules]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment.js]
[/mnt/c/ubuntu/erl-example/node_modules/react/lib/ExecutionEnvironment.json]
 @ ./~/enzyme/build/react-compat.js 73:4-45
 @ ./~/enzyme/build/ShallowWrapper.js
 @ ./~/enzyme/build/index.js
 @ ./test.js

@ljharb
Copy link
Member

ljharb commented Mar 13, 2017

Have you installed react-addons-test-utils manually, as specified in the readme?

@joetidee
Copy link
Author

yes and react-dom too.

@ljharb
Copy link
Member

ljharb commented Mar 14, 2017

@joetidee is everything in your package.json that starts with "react-" set to the same version range? If not, what's your package.json?

@joetidee
Copy link
Author

Yes, looks that way. Here is the package.json:

{
  "name": "erl-example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha-webpack test.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-cli": "^6.23.0",
    "babel-core": "^6.23.1",
    "babel-loader": "^6.4.0",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-react": "^6.23.0",
    "babel-preset-stage-0": "^6.22.0",
    "babel-register": "^6.23.0",
    "chai": "^3.5.0",
    "chai-enzyme": "^0.6.1",
    "enzyme": "^2.7.1",
    "enzyme-react-intl": "^1.4.1",
    "jsdom": "^9.12.0",
    "mocha": "^3.2.0",
    "mocha-webpack": "^0.7.0",
    "react-addons-test-utils": "^15.4.2",
    "react-dom": "^15.4.2",
    "source-map-support": "^0.4.11",
    "webpack": "^2.2.1",
    "webpack-node-externals": "^1.5.4"
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-intl": "^2.2.3"
  }
}

@ljharb
Copy link
Member

ljharb commented Mar 14, 2017

If npm ls exits zero, then I'm not sure :-/

@akalman
Copy link

akalman commented Apr 27, 2017

I can confirm that adding react/addons, react/lib/ExecutionEnvironment, and react/lib/ReactContext to externals in my webpack config worked for me. It seems like both 'react' and true worked as values.

as for @joetidee 's specific issue, I was able to solve them by npm installing react-test-renderer and making the following changes to the webpack conf.

     module: {
         rules: [{
             test: /\.js?$/,
-            use: ['babel-loader','react-loader']
+            use: ['babel-loader']
         },{
             test: /\.jsx?$/,
-            use: ['babel-loader?' + JSON.stringify({
-                presets: ["es2015", "stage-0", "react"]
-            })]
+            use: {
+                loader: 'babel-loader',
+                options: { presets: ['react'] }
+            }
         }]
     },

@the-spyke
Copy link

@ljharb But why do cheerio exists in externals? enzyme requires it directly and calls .load() from it. How passing the window object instead may work?

@ljharb
Copy link
Member

ljharb commented Sep 1, 2018

I'm going to close this; I'm not sure what there is to do here.

Happy to reopen if someone can provide a clear description of what needs changing; please feel free to file a new issue as well.

@ljharb ljharb closed this as completed Sep 1, 2018
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