question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After haul upgrade can't compile with TypeError: compilation.getAsset is not a function

See original GitHub issue

Environment

    "@haul-bundler/babel-preset-react-native": "^0.13.2",
    "@haul-bundler/cli": "^0.13.1",
    "@haul-bundler/inspector": "^0.13.0",
    "@haul-bundler/preset-0.60": "^0.13.0",
    "react-native": "^0.61.1",
     Node v10.16.0

Config:

// since preset-0.61 isn't yet available
import { withPolyfills, makeConfig } from '@haul-bundler/preset-0.60';

const removeRuleByTest = (moduleConfig, test) => {
  const index = moduleConfig.findIndex(rule => {
    if (rule.test) {
      return rule.test.toString() === test.toString();
    }
    return false;
  });
  moduleConfig.splice(index, 1);
};

export default makeConfig({
  bundles: {
    index: platform => ({
      entry: withPolyfills(`./src/index.${platform}.js`),
      transform({ config }) {
        // Remove babel-loader, as it handles both .ts(x) and .js(x) files
        removeRuleByTest(config.module.rules, /\.[jt]sx?$/);

        config.module.rules = [
          {
            exclude: /node_modules(?!.*[\/\\](react|@react-native-community|@haul-bundler))/,
            test: /\.tsx?$/,
            loader: 'ts-loader',
          },
          ...config.module.rules,

          // Re-add the babel-loader, now only for .js(x)
          {
            exclude: /node_modules(?!.*[\/\\](react|@react-native-community|@haul-bundler))/,
            test: /\.jsx?$/,
            loader: require.resolve('babel-loader'),
            options: {
              plugins: [require.resolve('@haul-bundler/core/build/utils/fixRequireIssues')],
            },
          },
          ...config.module.rules,
        ];

        config.resolve.extensions = [
          `.${platform}.ts`,
          '.mobile.ts',
          '.native.ts',
          `.${platform}.tsx`,
          '.mobile.tsx',
          '.native.tsx',
          '.ts',
          '.tsx',
          ...config.resolve.extensions,
        ];
      },
    }),
  },
});

Description

After upgrading to the new haul bundle from a working legacy instance and starting with a fresh config I seemingly can’t exclude things from Typescript checks and compilation terminates. Not sure what I’m missing or am I looking at an outdated config?

Traviss-MacBook-Pro:xc **$ yarn ios --haul-inspector
yarn run v1.16.0
$ NODE_OPTIONS=--max_old_space_size=8192 REACT_NATIVE=true NODE_ENV=development yarn haul start --platform ios --eager ios --haul-inspector
[Logs]

done ▶︎ Packager server running on http://localhost:8081
error ▶︎ /Users/**/**/xc/node_modules/@haul-bundler/core/node_modules/webpack/lib/SourceMapDevToolPlugin.js:179
const asset = compilation.getAsset(file).source;


TypeError: compilation.getAsset is not a function
at files.forEach (/Users/**/**/xc/node_modules/@haul-bundler/core/node_modules/webpack/lib/SourceMapDevToolPlugin.js:179:33)
at Array.forEach (<anonymous>)
at compilation.hooks.afterOptimizeChunkAssets.tap (/Users/**/**/xc/node_modules/@haul-bundler/core/node_modules/webpack/lib/SourceMapDevToolPlugin.js:178:12)
at SyncHook.eval [as call] (eval at create (/Users/**/**/xc/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:12:1)
at SyncHook.lazyCompileHook (/Users/**/**/xc/node_modules/tapable/lib/Hook.js:154:20)
at hooks.optimizeChunkAssets.callAsync.err (/Users/**/**/xc/node_modules/webpack/lib/Compilation.js:1313:42)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/**/**/xc/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/Users/**/**/xc/node_modules/tapable/lib/Hook.js:154:20)
at hooks.additionalAssets.callAsync.err (/Users/**/**/xc/node_modules/webpack/lib/Compilation.js:1309:36)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/**/**/xc/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/Users/**/**/xc/node_modules/tapable/lib/Hook.js:154:20)
at hooks.optimizeTree.callAsync.err (/Users/**/**/xc/node_modules/webpack/lib/Compilation.js:1305:32)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/**/**/xc/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/Users/**/**/xc/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/Users/**/**/xc/node_modules/webpack/lib/Compilation.js:1242:27)
at hooks.make.callAsync.err (/Users/**/**/xc/node_modules/webpack/lib/Compiler.js:546:17)
at _err0 (eval at create (/Users/**/**/xc/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:11:1)
at _addModuleChain (/Users/**/**/xc/node_modules/webpack/lib/Compilation.js:1093:12)
at processModuleDependencies.err (/Users/**/**/xc/node_modules/webpack/lib/Compilation.js:1005:9)
at process._tickCallback (internal/process/next_tick.js:61:11)

Reproducible Demo

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
DaveWellingcommented, Jul 10, 2020

Future googlers - FWIW - I had this error and was able to resolve it by uninstalling webpack and webpack-cli, then installing the latest version of those two.

1reaction
denielercommented, Apr 6, 2021

This issue was solved for me by upgrading webpack from 4.33 to 4.46 version. It looks like getAssets feature was added only in webpack version 4.40.

Read more comments on GitHub >

github_iconTop Results From Across the Web

After haul upgrade can't compile with TypeError: compilation ...
After haul upgrade can't compile with TypeError : compilation.getAsset is not a function.
Read more >
[6.2.7] [Webpack 5] [Laravel] [Vue] Cannot GET / #14565
I am in the middle of upgrading my webpack 4 stack to webpack 5 so I can use PostCSS 8 and Tailwind 2....
Read more >
TypeError: compiler.plugin is not a function - Stack Overflow
After running the build command, I get: TypeError: compiler.plugin is not a function. Removing new ExtractTextPlugin from the plugin ...
Read more >
Child compilation failed: Module.createRequire is not a function
Failed to compile.Module.createRequire is not a functionERROR in Module.createRequire is not a functionERROR in Error: Child compilation ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found