daun/laravel-mix-transpile-node-modules

Cannot read property 'toString' of undefined

Closed this issue · 7 comments

Currently experiencing this error

 TypeError: Cannot read property 'toString' of undefined
    at TranspileNodeModules.ruleTransformsJs (/Users/owen.soak/Sites/projectx/node_modules/laravel-mix-transpile-node-modules/index.js:69:26)
    at /Users/owen.soak/Sites/projectx/node_modules/laravel-mix-transpile-node-modules/index.js:64:22
    at Array.filter (<anonymous>)
    at TranspileNodeModules.findBabelRules (/Users/owen.soak/Sites/projectx/node_modules/laravel-mix-transpile-node-modules/index.js:63:18)
    at TranspileNodeModules.webpackConfig (/Users/owen.soak/Sites/projectx/node_modules/laravel-mix-transpile-node-modules/index.js:51:24)
    at /Users/owen.soak/Sites/projectx/node_modules/laravel-mix/src/components/ComponentRegistrar.js:124:54
    at /Users/owen.soak/Sites/projectx/node_modules/laravel-mix/src/Dispatcher.js:39:62
    at Array.map (<anonymous>)
    at Dispatcher.fire (/Users/owen.soak/Sites/projectx/node_modules/laravel-mix/src/Dispatcher.js:39:47)
    at Mix.dispatch (/Users/owen.soak/Sites/projectx/node_modules/laravel-mix/src/Mix.js:250:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 2

This is my webpack config

const mix = require('laravel-mix');
const path = require('path');
const fs = require('fs');
require('laravel-mix-postcss-config');
require('laravel-mix-polyfill');
require('laravel-mix-transpile-node-modules');
const TargetsPlugin = require('targets-webpack-plugin');
const {zip} = require('zip-a-folder');
const git = require('git-last-commit');

// Config
mix.setPublicPath('dist');

mix.alias({
  '@root': path.resolve(__dirname, ''),
  '@': path.resolve(__dirname, 'src'),
  '@data': path.resolve(__dirname, 'data'),
  '@utils': path.resolve(__dirname, 'src/app/utils'),
  '@atoms': path.resolve(__dirname, 'src/app/components/atoms'),
  '@molecules': path.resolve(__dirname, 'src/app/components/molecules'),
  '@organisms': path.resolve(__dirname, 'src/app/components/organisms'),
});

// Build
mix.js('src/app.js', 'dist')
  .react()
  .polyfill({
    enabled: true,
    entryPoints: 'all',
    useBuiltIns: 'usage',
    targets: {
      'ie': 11
    },
    corejs: 3
  })
  .postCssConfig({
    postcssOptions: {
      plugins: [
        require('tailwindcss'),
        require('postcss-prepend-selector')({selector: '[data-soak-widget] '})
      ]
    }
  });

// Copy index.html
mix.copy('index.html', 'dist/index.html')
  .after(() => {
    const filePath = path.resolve(__dirname, 'dist/index.html');
    fs.readFile(filePath, 'utf8', (err, data) => {
      fs.writeFile(filePath, data.replace('http://localhost:8080', '.'), () => {
      });
    });
  });

// Copy fonts
mix.copyDirectory('fonts', 'dist/fonts');

// Watch
mix.browserSync({
  open: false,
  ui: false,
  server: true
});

// Bundle Production
if (mix.inProduction()) {

  // Copy images if NETLIFY env
  // if (process.env.NETLIFY) {
  mix.copyDirectory('images', 'dist/images');
  // }
  // Copy Data
  mix.copy('data/data.json', 'dist/data/data.json')
    .after(() => {
      const filePath = path.resolve(__dirname, 'dist/data/data.json');
      fs.readFile(filePath, 'utf8', (err, data) => {
        fs.writeFile(filePath, JSON.stringify(JSON.parse(data)), () => {});
      });
    });

  /**
   * Transpile node_modules in production
   */
  mix.transpileNodeModules();

  mix.webpackConfig({
    plugins: [
      new TargetsPlugin({
        browsers: ['last 2 versions', 'chrome >= 41', 'IE 11'],
      }),
    ]
  });

  mix.then(() => {
    if (!process.env.NETLIFY) {
      git.getLastCommit(async (err, commit) => {
        await zip('dist', `bundle-${commit.shortHash}.zip`);
      });
    }
  });
}
daun commented

Looks like you only pasted the stack trace. The actual error message is missing.

Sorry @daun i've updated the above, looks like github cropped some of it off due to the code snippet starting with "[webpack-cli]"

daun commented

Does the error go away if you disable laravel-mix-polyfill? I can vaguely remember them not working together but haven't use polyfill myself.

Does the error go away if you disable laravel-mix-polyfill? I can vaguely remember them not working together but haven't use polyfill myself.

Removed this and the same error crops up.

daun commented

I'm afraid I'm not able to look into this at the moment and won't be for a few more weeks. If you decide to dig deeper and find a fix, I'm happy to take a pull request.

daun commented

This should be fixed in 2.0.4, please reopen the issue if you're still seeing it.