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

File loader error #348

Open
3 tasks
mjperales opened this issue Jan 18, 2019 · 2 comments
Open
3 tasks

File loader error #348

mjperales opened this issue Jan 18, 2019 · 2 comments

Comments

@mjperales
Copy link

mjperales commented Jan 18, 2019

  • System Information

    • [ Firefox 64] Browser type and version
    • [ Mojave] OS type and version
    • [ 10.15.0] Node version
    • [ Module parse failed: Unexpected token m in JSON at position 0 while parsing near 'module.exports = __w...] Any error messages that may be in the console where you ran npm start
    • Any error messages in the JS console
  • Describe the bug
    While trying to copy the web-app-manifest.json
    npm run build:prod

@eelayoubi
Copy link

Hello mjperales,
In case you are still having this issue, in your webpack/module.config.js, in the rules array, add the following rule:

{
        type: 'javascript/auto',
        test: /\.(json|html)/,
        exclude: /node_modules/,
        use: [{
          loader: 'file-loader',
          options: { name: '[name].[ext]' },
        }],
      }

and it will work fine, this will tell webpack to parse json using file-loader.

So your module.config.js will look like the following:

/* eslint-env node */

const extractSass = require('./extract-sass');

module.exports = function () {
  return {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader'
          },
          {
            loader: 'eslint-loader',
            options: {
              emitError: true
            }
          }
        ]
      },
      {
        type: 'javascript/auto',
        test: /\.(json|html)/,
        exclude: /node_modules/,
        use: [{
          loader: 'file-loader',
          options: { name: '[name].[ext]' },
        }],
      },
      {
        test: /\.scss$/,
        use: [
          'style-loader', // creates style nodes from JS strings
          'css-loader', // translates CSS into CommonJS
          {
            loader: 'sass-loader',
            options: {
              includePaths: ['node_modules/muicss/lib/sass']
            }
          }
        ]
      }
    ]
  };
};

@deschantkn
Copy link

deschantkn commented Sep 14, 2020

System Information

[ Chrome 85] Browser type and version
[ Catalina] OS type and version
[ 14.0.0] Node version

I am currently taking this workshop on Frontend Masters and I had the same issue. After updating my module.config.js webpack is successfully parsing JSON manifest however the contents are missing.

Here is what I see in my DevTools on chrome

Screen Shot 2020-09-14 at 12 11 29

Screen Shot 2020-09-14 at 12 11 41

Any help please? Thank you!

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

3 participants