Skip to content

Cannot read property 'replace' of undefined #4

Closed
@hulkish

Description

@hulkish

I'm running into the following issue while trying to use babel-plugin-react-css-modules@^1.1.0 with an experimental app I just created via create-react-app:

Failed to compile.

Error in ./src/components/calculator/index.js
Module build failed: TypeError: /Users/myuser/dev/sandbox/my-calculator-react-app/src/components/calculator/index.js: Cannot read property 'replace' of undefined
    at Array.map (native)
    at Array.map (native)
    at Array.map (native)
 @ ./src/containers/app-root/index.js 14:18-50

Here's my babel config:

{
  "presets": [
    "react-app"
  ],
  "plugins": [
    "react-css-modules"
  ]
}

Here's my webpack loaders config for my css & scss files:

{
  test: /\.css$/,
  loaders: [
    'style-loader?sourceMap',
    `css-loader?${JSON.stringify({
      importLoaders: 3,
      sourceMap: true,
      modules: true,
    })}`,
    'postcss-loader?sourceMap',
    "resolve-url-loader"
  ]
},
{
  test: /\.scss$/i,
  loaders: [
    'style-loader?sourceMap',
    `css-loader?${JSON.stringify({
      importLoaders: 3,
      sourceMap: true,
      modules: true,
    })}`,
    'postcss-loader?sourceMap',
    "resolve-url-loader",
    'sass-loader?sourceMap',
  ]
}

Here's a snippet of what my calculator.scss file looks like:

.calculator {
  display: block;
  padding: 0.2em 0.4em;
}

Here's my usage within my react component (and where the issue begins to occur):

import React, { Component } from 'react';
import './calculator.scss';// if i comment this line, the error goes away

class Calculator extends Component {
  render() {
    return (
      <div className="calculator">
        hi
      </div>
    );
  }
}

export default Calculator;

You can replicate this issue by cloning my repo: https://github.com/hulkish/calculator-app-exercise-react

Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions