DocSpring / craco-antd

A craco plugin to use Ant Design with create-react-app
MIT License
234 stars 49 forks source link

Cannot read property 'env' of undefined #6

Closed cemremengu closed 5 years ago

cemremengu commented 5 years ago

I am unable to start my app unless I failed to follow instructions. The error is: context.env === "production" ? sassRule.loader : sassRule.use;

package.json:

  "dependencies": {
    "@craco/craco": "^2.4.0",
    "antd": "^3.11.0",
    "craco-antd": "^1.5.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-scripts": "^2.1.1"
  },
  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test"
  },

craco.config.js

const CracoAntDesignPlugin = require("craco-antd");

module.exports = {
  plugins: [{ plugin: CracoAntDesignPlugin }]
};

Any ideas?

ndbroadbent commented 5 years ago

Hi, sorry I forgot to release a new version that works with the latest craco-less (a dependency). Could you please try updating craco-antd to 1.6.0 and try again? Thanks!

ndbroadbent commented 5 years ago

Actually yeah I'm very sure that's the issue, because I started passing thecontext through in version 1.6.0. Sorry about that, I could have sworn I released 1.6.0 last night, but forgot to run npm publish.

cemremengu commented 5 years ago

Thanks for the quick response! I am getting another error now though:

          } webpack config: ${loader}`,
                              ^

ReferenceError: loader is not defined
    at loaders.forEach.ruleOrLoader (C:\Users\node_modules\craco-less\lib\craco-less.js:112:31)

Should I update craco to latest?

EDIT: same error with craco ^3.2.0

ndbroadbent commented 5 years ago

Hi, sorry about that! That was an bug in my error handler because I was lazy with my tests. It was actually meant to throw an error, but I didn't test the error message.

But this means that it saw an unknown loader in your webpack config, which is really weird, because I'm testing with the same version of react-scripts, and running it in my own app as well.

Please update to craco-antd version 1.7.0, and then let me know what the error message says. Thanks!

cemremengu commented 5 years ago

I actually don't have a webpack config. I never needed one previously since cra took care of that. It's a fresh project with nothing in it. I am switching from react-app-rewired. Just followed antd + craco + craco-antd guidelines. Here is the error:

C:\Users\node_modules\cracoless\node_modules\@craco\craco\lib\plugin-utils.js:29

   throw new Error(
    ^

Error: Found an unhandled loader in the development webpack config: C:\Users\node_modules\style-loader\index.js

This error probably occurred because you updated react-scripts or craco. Please try updating craco-less to the latest version:

   $ yarn upgrade craco-less

Or:

   $ npm update craco-less

If that doesn't work, craco-less needs to be fixed to support the latest version.
Please check to see if there's already an issue in the FormAPI/craco-less repo:

   * https://github.com/FormAPI/craco-less/issues?q=is%3Aissue+webpack+unknown+rule

at throwUnexpectedConfigError (C:\Users\node_modules\cracoless\node_modules\@craco\craco\lib\plugin-utils.js:29:11
at throwError (C:\Users\node_modules\craco-less\lib\craco-less.js:10:7)
ndbroadbent commented 5 years ago

I actually don't have a webpack config

Sorry yes, I just mean the default webpack config that comes from create-react-app. I have some checks to make sure it doesn't change and break things.

So the reason for this error is that I forgot to support Windows. I had hardcoded the path separators as / (Mac and Linux) instead of \. Sorry about that!

I've just fixed this and added some tests for Windows, so now everything should be working. Please update to craco-antd version 1.9.0, which will pull in the fixed version of craco-less (1.5.0.)

P.S. I don't have a Windows machine to fully test this, so please let me know if you still run into any issues.

cemremengu commented 5 years ago

Works now! Thanks a lot for the help, I really appreciate it. Apologies for not being able to help by sending a PR, unfortunately my front-end skills are only enough to use tooling :)

I can suggest to turn on windows testing for travis if it helps, hopefully I can switch to linux soon 😄 Thanks again!

ndbroadbent commented 5 years ago

Awesome, and thanks for the tip! I didn't realize Travis CI supported Windows now, so that's awesome! I'll try to get the tests running on Windows as well.

thomasfl commented 5 years ago

When running running craco start with NODE_ENV set to production, the process prints out this exception. The problem was actually me trying to run craco in production mode. You should not run craco in production, you should run craco build. My suggestion is that craco exits with a polite error message telling you not to run craco in production mode.

$ NODE_ENV=production npm start

> sosialhjelp-innsyn@0.1.0 start /Users/thomasfl/workspace/sosialhjelp-innsyn
> craco start

/Users/thomasfl/workspace/sosialhjelp-innsyn/node_modules/@craco/craco/lib/plugin-utils.js:29
    throw new Error(
    ^

Error: Found an unhandled loader in the production webpack config: /Users/thomasfl/workspace/sosialhjelp-innsyn/node_modules/style-loader/index.js