codebandits / react-app-rewire-css-modules

MIT License
69 stars 51 forks source link

TypeError: Cannot match against 'undefined' or 'null'. #5

Closed kwinH closed 6 years ago

kwinH commented 6 years ago

code

/* config-overrides.js */
const path = require('path');
const {injectBabelPlugin} = require('react-app-rewired');
const rewireLess = require('react-app-rewire-less');
const rewireCssModules = require('react-app-rewire-css-modules');

module.exports = function override(config, env) {
  config = injectBabelPlugin(['import', {
    libraryName: 'antd-mobile',
    //style: 'css',
    style: true
  }], config);
  config = rewireLess.withLoaderOptions({
    modifyVars: {
      "@primary-color": "#1DA57A"
    },
  })(config, env);

  config = rewireCssModules(config, env);

  config.resolve.alias = {
    "@": path.join(__dirname, 'src/')
  };

  return config;
};

error

$ npm start

> antm-demo@0.1.0 start F:\code\react\antm-demo
> react-app-rewired start

F:\code\react\antm-demo\node_modules\react-app-rewire-css-modules\index.js:13
    const {index, rules} = findIndexAndRules(rulesSource, ruleMatcher)
                           ^

TypeError: Cannot match against 'undefined' or 'null'.
    at findRule (F:\code\react\antm-demo\node_modules\react-app-rewire-css-modules\index.js:13:28)
    at module.exports (F:\code\react\antm-demo\node_modules\react-app-rewire-css-modules\index.js:41:37)
    at Object.override [as webpack] (F:\code\react\antm-demo\config-overrides.js:19:12)
    at Object.<anonymous> (F:\code\react\antm-demo\node_modules\react-app-rewired\scripts\start.js:13:13)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! antm-demo@0.1.0 start: `react-app-rewired start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the antm-demo@0.1.0 start script 'react-app-rewired start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the antm-demo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-app-rewired start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs antm-demo
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls antm-demo
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\kwin\AppData\Roaming\npm-cache\_logs\2018-01-16T14_06_00_160Z-debug.log
BerndWessels commented 6 years ago

Yup, I get exactly the same error.

{
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  },
  "devDependencies": {
    "node-sass": "^4.7.2",
    "react-app-rewire-css-modules": "github:codebandits/react-app-rewire-css-modules",
    "react-app-rewire-hot-loader": "^1.0.0",
    "react-app-rewired": "^1.4.0",
    "react-hot-loader": "^3.1.3",
    "react-scripts": "1.1.0",
    "sass-loader": "^6.0.6"
  },
  "name": "microsite-platform",
  "private": true,
  "scripts": {
    "build": "react-app-rewired build",
    "eject": "react-scripts eject",
    "start": "react-app-rewired start",
    "test": "react-app-rewired test --env=jsdom"
  },
  "version": "0.1.0"
}
treasureDouDou commented 6 years ago

Yup, I get exactly the same error

lnhrdt commented 6 years ago

@kwinH, @BerndWessels, and @treasureDouDou thanks for reporting this issue. Apologies it has taken me so long to reply.

I believe this is related to #4 and the underlying issue that the code I wrote didn't work properly on Windows systems. I had only tested it on *nix systems. A fix has been merged to master. Please try to tool again and let me know if you have any further problems.

I'm confident the cause of @kwinH's issue was resolved based on his logs. If I'm wrong or you have any other problems please reopen this issue or submit another.

TabrisK commented 6 years ago

how to resolve the issue on windows

tantaiMoon commented 6 years ago

I still have this problem with Windows, my version is 1.1.0. how to resolve the issue on windows? @lnhrdt