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

Unexpected token : #450

Closed
davidsims9t opened this issue May 20, 2017 · 6 comments
Closed

Unexpected token : #450

davidsims9t opened this issue May 20, 2017 · 6 comments
Labels

Comments

@davidsims9t
Copy link

davidsims9t commented May 20, 2017

I'm getting an error in my readme file where JSON is presumably not recognized/loaded. The error is:

SyntaxError: Unexpected token (3:10)
1 <BasicCard cards={[
2 :   {
3 :     "type": "text",

My style guide config looks like:

module.exports = {
  components: 'src/@(bands|modules|components)/*.js',
  webpackConfig: require('./webpack.config.client.js'),
  getExampleFilename(componentPath) {
    return componentPath.replace('src', 'examples').replace(/\.jsx?$/, '.md');
  }
};

I'm using Webpack 2.2.1.

@sapegin
Copy link
Member

sapegin commented May 20, 2017

Please make an example as described here so I could reproduce the error..

@davidsims9t
Copy link
Author

davidsims9t commented May 22, 2017

@sapegin Sure I wrote a simple component and failing test.

export default class Test extends React.Component {
render() {
return (
<div></div>
);
}

Test:

<Test test={{"key": "value"}} />

I'm getting the same error as I mentioned above. I'm testing it on Google Chrome 59.0. I'm using React 15.4.2.

Here's what my webpack.config file looks like:

module.exports = {
  target: 'web',
  entry: {
     client: path.join(__dirname, 'client.js')
  },
  output: {
    path: path.join(__dirname, './build/public'),
  },
  externals: {
    'react/addons': true,
    'react/lib/ExecutionEnvironment': true,
    'react/lib/ReactContext': true
  },
  resolveLoader: {
    modules: [
      `${__dirname}/src`,
      `${__dirname}/node_modules`
    ],
    extensions: ['.json', '.js', '.jsx', '.css', '.less']
  },
  resolve: {
    modules: [
      `${__dirname}/src`,
      `${__dirname}/node_modules`
    ],
    extensions: ['.json', '.js', '.jsx', '.css', '.less']
  },
  module: {
    rules: [
      {
        test: /\.js(x)?$/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.json$/,
        use : 'json-loader'
      }
    ]
  }
}

Hopefully this is enough context.

@sapegin
Copy link
Member

sapegin commented May 22, 2017

I can’t reproduce it in an example style guide.

Please make an example as described here so I could reproduce the error..

@davidsims9t
Copy link
Author

I was able to eliminate the error by removing my resolver/resolveLoader properties from my Webpack build. This seems to be causing the error. Unfortunately I need custom resolvers. Is there a way to get around this?

@sapegin
Copy link
Member

sapegin commented May 23, 2017

Looks like you have the same issue as #359. Maybe try to use node_modules instead of ${__dirname}/node_modules.

@davidsims9t
Copy link
Author

@sapegin That was the same issue I had. It's working perfectly now. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants