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.

some type-only TS files are ignored when using `tsconfig` `files`?

See original GitHub issue

What happens and why it is incorrect

there are many files ending in *.ts in the src, but only some have been transpiled

  1. Does tsc have the same output? If so, please explain why this is incorrect behavior

NO, tsc run as expectly. image

here’s file structure: image

but rpt2 seems to ignore the file named component.ts: image

Environment

Versions

System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 59.11 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v14.17.4/bin/yarn
    npm: 6.14.14 - ~/.nvm/versions/node/v14.17.4/bin/npm
  npmPackages:
    rollup: ^2.45.2 => 2.45.2
    rollup-plugin-typescript2: ^0.30.0 => 0.30.0
    typescript: ^4.3.5 => 4.3.5
  npmGlobalPackages:
    typescript: 4.3.5

rollup.config.js

:
import { nodeResolve } from '@rollup/plugin-node-resolve';

import replace from '@rollup/plugin-replace';
import postcss from 'rollup-plugin-postcss';
import image from '@rollup/plugin-image';
import ts from 'rollup-plugin-typescript2';
import dts from 'rollup-plugin-dts';
import json from '@rollup/plugin-json';
import alias from '@rollup/plugin-alias';
import autoExternal from 'rollup-plugin-auto-external';
import path from 'path';
import importCss from './rollup-plugin-import-css';

const resolve = (...dirs) => path.resolve(__dirname, '../', ...dirs);

function toUpperCase(match) {
  return match.replace('-', '').toUpperCase();
}

export default [
  {
    input: resolve('src/lib/index.tsx'),
    output: [
      {
        file: resolve('dist/index.esm.js'),
        format: 'es',
        sourcemap: true,
      },
    ],

    external: id => {
      try {
        const idSourcePath = require.resolve(id, { paths: [resolve()] });
        return idSourcePath && idSourcePath.includes('node_modules');
      } catch (error) {
        return false;
      }
    },
    plugins: [
      ts({
        check: false,
        tsconfig: resolve('tsconfig.json'),
        tsconfigOverride: {
          compilerOptions: { declaration: true, declarationDir: resolve('dist/type') },
        },
        verbosity: 2,
        useTsconfigDeclarationDir: true,
        include: ['*.ts+(|x)', '**/*.ts+(|x)', '*.js+(|x)', '**/*.js+(|x)'],
      }),
      image(),
      postcss({
        extensions: ['.css', '.scss', '.less'],
        autoModules: true,
        extract: 'index.css',
        namedExports(name) {
          let reg = /-[a-z]/g;
          const temp = name.replace(reg, toUpperCase);
          return temp;
        },
      }),
      json(),
      alias({
        entries: [
          {
            find: 'src',
            replacement: resolve('src'),
          },
        ],
      }),
      nodeResolve({
        extensions: ['.js', '.jsx', '.ts', '.tsx'],
        // some package.json files have a "browser" field which specifies
        // alternative files to load for people bundling for the browser. If
        // that's you, either use this option or add "browser" to the
        // "mainfields" option, otherwise pkg.browser will be ignored
        browser: true,
        preferBuiltins: true,
        mainFields: ['browser', 'jsnext', 'module', 'main'],
      }),
      replace({
        'process.env.NODE_ENV': JSON.stringify('development'),
        'process.env.SEMI_ICON_LAZY_LOAD': true,
        preventAssignment: true,
      }),
      autoExternal({
        packagePath: resolve(),
      }),
      importCss(),
    ],
  },
  {
    input: resolve('dist/type/src/lib/index.d.ts'),
    external: id => {
      try {
        const idSourcePath = require.resolve(id, { paths: [resolve()] });
        return idSourcePath && idSourcePath.includes('node_modules');
      } catch (error) {
        return false;
      }
    },
    output: [{ file: resolve('dist/index.d.ts'), format: 'es' }],
    plugins: [dts()],
  },
];

tsconfig.json

:
{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "lib": ["es7", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "rootDir": "./",
    "baseUrl": "./src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": false,
    "noImplicitAny": false,
    "importHelpers": true,
    "strictNullChecks": false,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "noEmit": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": false,
    "paths": {
      "@ies/kefu-editor": ["src/lib/*"]
    },
    "plugins": [
      {
        "transform": "ts-optchain/transform"
      }
    ]
  },
  "typeRoots": ["node", "node_modules/@types", "./src/typings"],
  "exclude": ["node_modules"]
}

package.json

:

plugin output with verbosity 3

:
/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx → dist/index.esm.js...
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "inlineSourceMap": false,
    "outDir": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/.cache/rollup-plugin-typescript2/placeholder",
    "moduleResolution": 2,
    "allowNonTsExtensions": true
}
rpt2: parsed tsconfig: {
    "options": {
        "isolatedModules": false,
        "declaration": true,
        "target": 2,
        "module": 99,
        "lib": [
            "lib.es2016.d.ts",
            "lib.dom.d.ts"
        ],
        "sourceMap": true,
        "allowJs": true,
        "jsx": 2,
        "moduleResolution": 2,
        "experimentalDecorators": true,
        "rootDir": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable",
        "baseUrl": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src",
        "forceConsistentCasingInFileNames": true,
        "noImplicitReturns": true,
        "noImplicitThis": false,
        "noImplicitAny": false,
        "importHelpers": true,
        "strictNullChecks": false,
        "suppressImplicitAnyIndexErrors": true,
        "noUnusedLocals": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": false,
        "paths": {
            "@ies/kefu-tag-table": [
                "src/lib/*"
            ]
        },
        "plugins": [
            {
                "transform": "ts-optchain/transform"
            }
        ],
        "declarationDir": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/dist/type",
        "configFilePath": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/tsconfig.json",
        "pathsBasePath": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable",
        "noEmitHelpers": false,
        "noResolve": false,
        "noEmit": false,
        "inlineSourceMap": false,
        "outDir": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/.cache/rollup-plugin-typescript2/placeholder",
        "allowNonTsExtensions": true
    },
    "fileNames": [
        "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "files": [
            "src/lib/index.tsx"
        ],
        "compilerOptions": {
            "isolatedModules": false,
            "declaration": true,
            "target": "es6",
            "module": "esnext",
            "lib": [
                "es7",
                "dom"
            ],
            "sourceMap": true,
            "allowJs": true,
            "jsx": "react",
            "moduleResolution": "node",
            "experimentalDecorators": true,
            "rootDir": "./",
            "baseUrl": "./src",
            "forceConsistentCasingInFileNames": true,
            "noImplicitReturns": true,
            "noImplicitThis": false,
            "noImplicitAny": false,
            "importHelpers": true,
            "strictNullChecks": false,
            "suppressImplicitAnyIndexErrors": true,
            "noUnusedLocals": true,
            "allowSyntheticDefaultImports": true,
            "esModuleInterop": false,
            "paths": {
                "@ies/kefu-tag-table": [
                    "src/lib/*"
                ]
            },
            "plugins": [
                {
                    "transform": "ts-optchain/transform"
                }
            ],
            "declarationDir": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/dist/type"
        },
        "typeRoots": [
            "node",
            "node_modules/@types",
            "./src/typings"
        ],
        "exclude": [
            "node_modules"
        ],
        "compileOnSave": false
    },
    "errors": [],
    "wildcardDirectories": {},
    "compileOnSave": false
}
rpt2: typescript version: 4.3.5
rpt2: tslib version: 2.1.0
rpt2: rollup version: 2.45.2
rpt2: rollup-plugin-typescript2 version: 0.30.0
rpt2: plugin options:
{
    "check": false,
    "tsconfig": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/tsconfig.json",
    "tsconfigOverride": {
        "compilerOptions": {
            "declaration": true,
            "declarationDir": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/dist/type"
        }
    },
    "verbosity": 3,
    "useTsconfigDeclarationDir": true,
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)",
        "*.js+(|x)",
        "**/*.js+(|x)"
    ],
    "clean": false,
    "cacheRoot": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/.cache/rollup-plugin-typescript2",
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false,
    "cwd": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable",
    "typescript": "version 4.3.5"
}
rpt2: rollup config:
{
    "input": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx",
    "plugins": [
        {
            "name": "rpt2"
        },
        {
            "name": "image"
        },
        {
            "name": "postcss"
        },
        {
            "name": "json"
        },
        {
            "name": "alias"
        },
        {
            "name": "node-resolve"
        },
        {
            "name": "replace"
        },
        {
            "name": "auto-external"
        },
        {},
        {
            "name": "stdin"
        }
    ],
    "output": [
        {
            "file": "/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/dist/index.esm.js",
            "format": "es",
            "plugins": [],
            "sourcemap": true
        }
    ]
}
rpt2: tsconfig path: /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/tsconfig.json
rpt2: included:
[
    "*.ts+(|x)",
    "**/*.ts+(|x)",
    "*.js+(|x)",
    "**/*.js+(|x)"
]
rpt2: excluded:
[
    "*.d.ts",
    "**/*.d.ts"
]
rpt2: Ambient types:
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/babel__core/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/babel__generator/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/babel__template/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/babel__traverse/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/color-name/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/css-modules-loader-core/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/estree/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/graceful-fs/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/hast/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/istanbul-lib-coverage/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/istanbul-lib-report/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/istanbul-reports/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/jest/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/json-schema/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/mdast/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/node/ts3.7/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/normalize-package-data/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/parse-json/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/parse5/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/prettier/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/prop-types/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/q/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/react/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/react-dom/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/resolve/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/stack-utils/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/unist/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/yargs/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/yargs-parser/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/json-schema/index.d.ts
rpt2:     /Users/bytedance/node_modules/@types/json5/index.d.ts
rpt2:     /Users/bytedance/node_modules/@types/minimist/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/node/ts3.7/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/normalize-package-data/index.d.ts
rpt2:     /Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/@types/parse-json/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx'
rpt2:     cache: '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/.cache/rollup-plugin-typescript2/rpt2_9e69c65b2d74fee0ad388d42568ea4ce7ba1b27d/code/cache/7cdbf1c7db69c2fd53815824bca49513a129c642'
rpt2:     cache miss
rpt2: generated declarations for '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx'
rpt2: dependency '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/utils.ts'
rpt2:     imported by '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx'
rpt2: resolving './utils' imported by '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx'
rpt2:     to '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/utils.ts'
rpt2: dependency '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/mock.ts'
rpt2:     imported by '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx'
rpt2: resolving './mock' imported by '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx'
rpt2:     to '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/mock.ts'
rpt2: transpiling '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/mock.ts'
rpt2:     cache: '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/.cache/rollup-plugin-typescript2/rpt2_9e69c65b2d74fee0ad388d42568ea4ce7ba1b27d/code/cache/a3be5c51ebb3fef03fc9a43c539d188ad1577216'
rpt2:     cache hit
rpt2: generated declarations for '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/mock.ts'
rpt2: transpiling '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/utils.ts'
rpt2:     cache: '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/node_modules/.cache/rollup-plugin-typescript2/rpt2_9e69c65b2d74fee0ad388d42568ea4ce7ba1b27d/code/cache/d1d6e9acec5e9e0b4392fcbc5bf623dab081aa31'
rpt2:     cache hit
rpt2: generated declarations for '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/utils.ts'

rpt2: generating target 1
rpt2: rolling caches
rpt2: emitting declarations for '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/index.tsx' to '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/dist/type/src/lib/index.d.ts'
rpt2: emitting declarations for '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/mock.ts' to '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/dist/type/src/lib/mock.d.ts'
rpt2: emitting declarations for '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/src/lib/utils.ts' to '/Users/bytedance/Public/helpdesk-semi-ui/packages/KefuCascaderTable/dist/type/src/lib/utils.d.ts'
(!) Broken sourcemap
https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect
Plugins that transform code (such as 'at position 9') should generate accompanying sourcemaps
created dist/index.esm.js in 2.7s

User/dist/type/src/lib/index.d.ts → dist/index.d.ts...
[!] Error: Could not resolve './component' from dist/type/src/lib/index.d.ts
Error: Could not resolve './component' from dist/type/src/lib/index.d.ts

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ZHHHH9980commented, Aug 18, 2022

@agilgur5 minimal repro: https://github.com/ZHHHH9980/mini-demo

npm install && npm run build:esm

will get the same error: image

Hope that will help.

0reactions
agilgur5commented, Sep 12, 2022

#406 has been merged and released in 0.34.0.

I also did not get the error you did in your logs when using your repro with 0.34.0 (there’s another error, but that’s unrelated to rpt2).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow tsconfig.json when input files are specified · Issue #27379
In my opinion, the right implementation should be: If no --project or -p option: Ignore tsconfig.json; Otherwise: Use the configuration file ...
Read more >
Why is the TypeScript compiler ignoring tsconfig.json?
Options are set to compile on save. When you save a file it is automatically compiling that single file and files imported on...
Read more >
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Read more >
TS - Skipping files with no tsconfig.json - Sonar Community
Even though SonarQube finds the tsconfig.json file, it keeps ignoring all of the typescript files in the project and it is only analyzing ......
Read more >
Understanding TypeScript's “Compilation Process” & the ...
You can manually provide a path to the tsconfig.json file using ... We want to compile all the .ts files except the ignore.ts...
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