Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

56
Vistas
After upgrading Angular, webpack module source-map-loader is throwing "this.getOptions is not a function"

I am currently building my angular project via webpack with source-map-loader to extract source maps, like so:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: "pre",
        use: ["source-map-loader"],
      },
    ],
  },
};

This works fine with my Angular 11 build. Once I upgrade my angular packages to Angular 12, I begin to get the following error:

Module build failed (from ./node_modules/source-map-loader/dist/cjs.js):
TypeError: this.getOptions is not a function
    at Object.loader (./node_modules/source-map-loader/dist/index.js:21:24)

Removing this section from my webpack module allows the build to succeed but I am no longer extracting the source maps, causing my bundle to increase in size.

I have tried upgrading source-map-loader to latest version and did not change the error. I have dug into the node_module and it is complaining about this section of code:

async function loader(input, inputMap) {
  const options = this.getOptions(_options.default);

I have seen may other questions on here in regards to sass-loader and other style loaders for Vue but this is for Angular and is mad about extracting source maps.

There are some breaking changes when going to Angular 12 but upgrading to webpack 5.0.0 did not seem to make a difference

What are some other things I can do to debug this?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

By looking at the source code v1.1.3 we do see

import { getOptions } from "loader-utils";

But after v2.0 or even v3.0, this import was deleted.

It came from the library loader-utils

Since v2.0, package.json doesn't import it anymore.

Looks like it has been deprecated, getOptions should be use from Webpack type instead of loader-utils.

Maybe your error come from a conflict with an old dependencie from your node_modules, you should remove the old one from your directory and try again

rm -rf node_modules/@types/loader-utils
rm -rf node_modules/loader-utils
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.