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

Cannot read property '.css' of undefined #97

Open
agungsb opened this issue Jun 24, 2017 · 1 comment
Open

Cannot read property '.css' of undefined #97

agungsb opened this issue Jun 24, 2017 · 1 comment

Comments

@agungsb
Copy link

agungsb commented Jun 24, 2017

Hi, I got the following error when using this plugin:

..\node_modules\css-modules-require-hook\lib\attachHook.js:10 Uncaught TypeError: Cannot read property '.css' of undefined

My usage:

const hook = require('css-modules-require-hook');
hook({
    // the custom template for the generic classes
    extensions: ['.css'],
    generateScopedName: '[name]__[local]___[hash:base64:5]',
    camelCase: true
});
import styles from './CircularProgressButton.css';

For your additional information, I'm using Webpack 3 and Babel 6. The project is using the ejected Create React App (CRA).

Any thoughts of how to solve this? Thanks.

@mightyaleksey
Copy link
Member

mightyaleksey commented Jan 8, 2018

You need to put the import call to another file. Compilers usually hoist them to the beginning of the file (as the spec defines imports are static and should be written at the top of file), so the css file will be called before the hook was attached.

// index.js
const hook = require('css-modules-require-hook');
hook({
    // the custom template for the generic classes
    extensions: ['.css'],
    generateScopedName: '[name]__[local]___[hash:base64:5]',
    camelCase: true
});

require('./app');
// app.js
import styles from './CircularProgressButton.css';

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

2 participants