Skip to content

ERROR failed to read input source map: failed to find input source map file "index.js.map" when setting useLegacyTypescriptPlugin to false #32671

Description

@shubhamdhingra007

Current Behavior

I was running NX build locally when I saw this warning:
Image

So, I simply added the configuration useLegacyTypescriptPlugin: false to our rollup configuration and tried running build command and now I get a series of errors like:

ERROR  failed to read input source map: failed to find input source map file "index.js.map" in [path-to-index.ts] files

I tried removing NX cache and the hack we have earlier added to filter out rpt2 plugin from the original issue, but nothing helps.

Expected Behavior

There shouldn't be any error when switching to official rollup TS plugin. A minimal change like removing that hack of filtering rpt2 plugin simply should be good enough.

GitHub Repo

No response

Steps to Reproduce

  1. Add the rollup config useLegacyTypescriptPlugin: false,
  2. Remove the hack for filtering rpt2 plugin
  3. Build npx nx run [package-name]:build

Nx Report

Node           : 20.19.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.8.2

nx                 : 21.3.11
@nx/js             : 21.3.11
@nx/eslint         : 21.3.11
@nx/workspace      : 21.3.11
@nx/devkit         : 21.3.11
@nx/eslint-plugin  : 21.3.11
@nx/rollup         : 21.3.11
@nx/vite           : 21.3.11
@nx/web            : 21.3.11
typescript         : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/rollup/plugin
@nx/eslint/plugin
@nx/vite/plugin
@nx/js/typescript
---------------------------------------
Cache Usage: 37.45 KB / 46.04 GB

Failure Logs

/Users/[path-to-repo]/packages/[custom-eslint-package]/src/index.ts → dist, dist...
  ERROR  failed to read input source map: failed to find input source map file "index.js.map" in "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/index.ts" file as either "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/index.js.map" or with appended .map
    at /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/swc-36.0.0/src/lib.rs:398

  ERROR  failed to read input source map: failed to find input source map file "index.js.map" in "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/index.ts" file as either "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/index.js.map" or with appended .map
    at /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/swc-36.0.0/src/lib.rs:398

  ERROR  failed to read input source map: failed to find input source map file "index.js.map" in "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/no-raw-colors/index.ts" file as either "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/no-raw-colors/index.js.map" or with appended .map
    at /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/swc-36.0.0/src/lib.rs:398

  ERROR  failed to read input source map: failed to find input source map file "index.js.map" in "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/no-deprecated-tokens/index.ts" file as either "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/no-deprecated-tokens/index.js.map" or with appended .map
    at /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/swc-36.0.0/src/lib.rs:398

  ERROR  failed to read input source map: failed to find input source map file "index.js.map" in "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/no-internal-tokens/index.ts" file as either "/Users/[path-to-repo]/packages/[custom-eslint-package]/src/plugins/no-internal-tokens/index.js.map" or with appended .map
    at /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/swc-36.0.0/src/lib.rs:398

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

This is our rollup config before and after. The after one is giving the error.

Before

const { withNx } = require('@nx/rollup/with-nx');

const config = withNx(
  {
    main: './src/index.ts',
    outputPath: './dist',
    tsConfig: './tsconfig.lib.json',
    compiler: 'swc',
    format: ['esm', 'cjs'],
  },
  {
    plugins: [renameCjsPlugin()],
    // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
    // e.g.
    // output: { sourcemap: true },
  }
);

// HACK: Remove the rpt2 plugin from the config
// This is a workaround to avoid the rpt2 plugin from being used, as it conflicts with the swc compiler.
// Issue at https://github.com/nrwl/nx/issues/30488
// Solution at https://github.com/ThePlenkov/astro-rollup-issue/pull/1/files
if (config.plugins) {
  config.plugins = config.plugins.filter((plugin) => {
    return plugin.name !== 'rpt2';
  });
}

/**
 * Renames .cjs.js files to .cjs
 * This lets the build still mostly be executed by NX while building both ESM and CJS bundles
 * NX outputs a .cjs.js file by default. When loaded in a CJS module (e.g. custom-eslint-package repo), as this ends in .js it's evaluated
 * as if it's a ESM module because package uses `type: module`.
 * Renaming to .cjs allows the module to be interpreted as CJS while keeping `type: module` inside package.
 * @returns {{name: string, generateBundle(*, *): void}}
 */

function renameCjsPlugin() {
  return {
    name: 'rename-cjs-extension',
    generateBundle(_, bundle) {
      for (const fileName of Object.keys(bundle)) {
        if (fileName.endsWith('.cjs.js')) {
          const asset = bundle[fileName];
          const newFileName = fileName.replace(/\.cjs\.js$/, '.cjs');

          delete bundle[fileName];
          bundle[newFileName] = { ...asset, fileName: newFileName };
        }
      }
    },
  };
}

module.exports = config;

After

const { withNx } = require('@nx/rollup/with-nx');

const config = withNx(
  {
    main: './src/index.ts',
    outputPath: './dist',
    tsConfig: './tsconfig.lib.json',
    compiler: 'swc',
    format: ['esm', 'cjs'],
    useLegacyTypescriptPlugin: false,
  },
  {
    plugins: [renameCjsPlugin()],
    // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
    // e.g.
    // output: { sourcemap: true },
  }
);

/**
 * Renames .cjs.js files to .cjs
 * This lets the build still mostly be executed by NX while building both ESM and CJS bundles
 * NX outputs a .cjs.js file by default. When loaded in a CJS module (e.g. custom-eslint-package repo), as this ends in .js it's evaluated
 * as if it's a ESM module because package uses `type: module`.
 * Renaming to .cjs allows the module to be interpreted as CJS while keeping `type: module` inside package.
 * @returns {{name: string, generateBundle(*, *): void}}
 */

function renameCjsPlugin() {
  return {
    name: 'rename-cjs-extension',
    generateBundle(_, bundle) {
      for (const fileName of Object.keys(bundle)) {
        if (fileName.endsWith('.cjs.js')) {
          const asset = bundle[fileName];
          const newFileName = fileName.replace(/\.cjs\.js$/, '.cjs');

          delete bundle[fileName];
          bundle[newFileName] = { ...asset, fileName: newFileName };
        }
      }
    },
  };
}

module.exports = config;

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions