Closed ZHHHH9980 closed 2 years ago
You didn't answer question 2 and 3 of the issue template, and did not provide a package.json
either. Please don't skip pieces of the issue template, they are there for a reason.
Specifically, I noted that there's 9 other plugins and a TS transformer and other complexity here, so it's far from a minimal repro, and a repro itself was not provided. The plugin order also does not match this plugin's compatibility list, and no rationale was given for why either.
Per the versions listed, you're also on an older version of rpt2, 0.30.0
, and not the current 0.32.1
.
Given the lack of repro, I can only hypothesize why this may occur, as no further investigation is possible without a repro. At the very least the contents of component.ts
and the file(s) that import it must be known in order to diagnose.
Without knowing the contents of the files, the only edge-cases in rpt2 are around type-only imports, i.e. #211 (which will soon be fixed by #406). Given that this produces a .js
file with tsc
, it doesn't seem to be a type-only import. And given that you're not using files
anyway, the current workaround mentioned in https://github.com/ezolenko/rollup-plugin-typescript2/issues/211#issuecomment-594234636 should work as well.
~So this does not seem to be caused by #211 or related to type-only imports (unless there's a detail I'm missing here)~
That's the only existing issue (that has a repro) that I can think of off the top of my head that might cause this kind of problem ~and it does not seem to be the culprit~.
As such, there's really nothing else that can be done without a repro. Please provide a minimal repro as the issue template requests.
EDIT: Per the repro provided below, component.ts
is in fact a type-only file. So will have to check why the workaround for #211 isn't working in this case.
@agilgur5 minimal repro: https://github.com/ZHHHH9980/mini-demo
npm install && npm run build:esm
will get the same error:
Hope that will help.
Thanks for the repro @ZHHHH9980, this helps quite a bit. Per the repro provided, component.ts
is in fact a type-only file.
So this is impacted by #211 and may just be a duplicate of that. Note that #211 has a fix out in #406.
That being said, I'm not sure why the workaround (from #175) isn't working in this case. I'll have to investigate that with the repro. This might be fixable with a simple change to the tsconfig
include
.
minimal
Just to clarify, the issue template defines "minimal" with the oft-cited StackOverflow explanation. This is a "repro" but it is not minimal because there are still, as I previously mentioned, many other plugins in use and large files etc that complicate the reproduction. Per the same line in the issue template, we actually provide a sample environment that we recommend using. That sample env is quite minimal, so a "minimal repro" would add the minimum changes to that in order to exhibit the problematic / buggy behavior.
That being said, I'm not sure why the workaround (from #175) isn't working in this case. I'll have to investigate that with the repro. This might be fixable with a simple change to the
tsconfig
include
.
So your repro has a different tsconfig.json
than the one you posted in your opening comment of the issue. In particular you are using tsconfig
files
. And as component.ts
is a type-only file, it doesn't get detected by Rollup.
So this duplicates #211, which will be fixed by #406.
That being said, since this is a duplicate and you are using files
(i.e. this is not a new issue), the workarounds available will work for your situation as well. This workaround and is simple available right now: add component.ts
to your files
list
"files": ["src/lib/index.tsx", "src/lib/component.ts"],
This will get TS to detect the file and rpt2 will generate declarations for it.
That workaround should suffice in the meantime until #406 is reviewed, merged, and released.
What happens and why it is incorrect
there are many files ending in
*.ts
in the src, but only some have been transpiledtsc
have the same output? If so, please explain why this is incorrect behaviorNO,
tsc
run as expectly.here's file structure:
but rpt2 seems to ignore the file named
component.ts
:Environment
Versions
```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()], }, ]; ```
:rollup.config.js
```json5 { "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"] } ```
:tsconfig.json
```json ```
:package.json
```text /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 ```plugin output with verbosity 3
: