Closed mokone91 closed 10 months ago
Please do not remove the issue template, it is there for a reason.
There are too few details here since the issue template was not used and no repro was provided to really be able to diagnose in any way.
That being said, 0.31.1
is ~2 years old. #332 was a sizeable fix to monorepo symlinks that was released in 0.32.0
and there were many, many other critical fixes since then (since I became a maintainer).
The previous behavior could very well have been a bug.
Sorry for that, next time i will use template.. Yeah, that's legacy build config and we do not touch it long time. but now one of our dependency add new modules tyes so I start to catch errors like
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
node_modules/@vueuse/core/index.d.cts (13:5)
11: * @param cancelCallback The provided callback is invoked when a re-evaluation of the computed value is triggered before the previous one finished
12: */
13: type AsyncComputedOnCancel = (cancelCallback: Fn) => void;
version 0.35 handles this fine, but extra folder for types appear.. Im not sure if it was a bug before - I do not use declarationDir so types should appear in the same place as transpired code - so behavior was fine before.
This is not reproduces in the single repo with exactly the same build config(it extracted to separate package and reused around multiple repos) And 'src' folder disappears when i remove import from another package(i import simple .json with tailwind theme) Package from which I import is added to target package dependency
version 0.35 handles this fine, but extra folder for types appear.. Im not sure if it was a bug before - I do not use declarationDir so types should appear in the same place as transpired code - so behavior was fine before.
That sounds like a rootDir
misconfiguration. That's not a bug though. See https://github.com/ezolenko/rollup-plugin-typescript2/issues/275#issuecomment-1107881058 for an explanation of how rootDir
works.
And 'src' folder disappears when i remove import from another package(i import simple .json with tailwind theme)
TS infers the rootDir
if it is not specified. In this case, it sounds like you're importing from a sibling directory, which changes the inferred rootDir
. For monorepos, if you're using paths
, that can also cause some issues. See https://github.com/ezolenko/rollup-plugin-typescript2/issues/112#issuecomment-1120350360 and #201.
As you removed the issue template, you also did not provide a tsconfig
or your rpt2 or Rollup configurations. This causes a lot of unnecessary and inefficient blind guesswork as a result.
I'm guessing that older versions probably didn't pick up the path correctly as symlinks just didn't work. You might've been missing some typings or had some incorrect typings when importing due to that.
Sorry for that, next time i will use template..
It would be good to edit your current issue as well. It's still missing plenty of relevant details, as I have mentioned a few times. Keep in mind that most of OSS is run by volunteers (including me). Please be respectful of volunteers' time, such as by filling out the minimum details that a repository asks for in an issue template.
ticket updated with more details I have try to add rootDir: './src' to package tsconfig.json - and now it getting error:
[!] (plugin rpt2) Error: src/hooks/useResponsive/useResponsive.ts:1:21 - error TS6059: File '/Users/...../ui-next/packages/ui-components/node_modules/@mycompany/styles/screens.json' is not under 'rootDir' '/Users/..../ui-next/packages/ui-components/src'. 'rootDir' is expected to contain all source files.
The file is in the program because:
Imported via '@mycompany/styles/screens.json' from file '/Users/..../ui-next/packages/ui-components/src/hooks/useResponsive/useResponsive.ts' with packageId '@mycompany/styles/screens.json@6.8.1'
Root file specified for compilation
1 import screens from '@mycompany/styles/screens.json';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/hooks/useResponsive/index.ts
that was expected, but the resolution(If i get it right) is to add 'reference' path to tsconfig file in related package - but there is no tsconfig there as this is simple package with .css and .json anyway, when i added symple tsconfig to styles package - build error still appear
Thank you for filling out the issue template. You are missing the rpt2 verbose log, but I don't think that's necessary in this case.
- Does
tsc
have the same output? If so, please explain why this is incorrect behavior N/A
This is applicable and tsc
does have the same output. The error is directly from the TS compiler. The error is correct.
So this isn't a bug, but you can workaround it in a few different ways:
package.json#types
to src
@mycompany/styles/screens.json
to your tsconfig
exclude
and then the rootDir
will now be calculated as src
again.
rootDir
is indeed up one levelBased on your error message, I think this indeed just failed to resolve the symlink in older versions, so it couldn't tell where the directory was.
3. Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction N/A
It actually would not be difficult to reproduce this, although the pnpm
bits wouldn't work with Stackblitz specifically. This would happen with any directory structure like yours where you import from a sibling directory.
Troubleshooting
Does
tsc
have the same output? If so, please explain why this is incorrect behavior N/ADoes your Rollup plugin order match this plugin's compatibility? If not, please elaborate yes
Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction N/A
What happens and why it is incorrect
Hi! After upgrading from 0.31.1 to 0.35.0 build for types containing extra 'src' dir, code transpiled fine(same as before package update). I use pnpm workspaces in my project. After investigation I found that id I remove import from another package(import screens from @mycompany/styles) - types generated correctly. I do not have any 'path' or 'rootDir' configured in any repos tsconfigs, and I do not use aliases.
my repo is huge, not sure if I can to extract working example..
UPD: Have test different package versions, seems extra types folder starts to appear in 0.33.0
Environment
pnpm monorepo
Versions
```js return { input: getInput(config), // simple glob to 'src/' output, plugins: [ ...getDepsPlugins(config), // depends on build target we add nodeExternals or not json(), replace({ 'process.env.NODE_ENV': JSON.stringify('production'), preventAssignment: true, }), // Only use typescript for declarations - babel will // do actual js transformations typescript({ useTsconfigDeclarationDir: false, emitDeclarationOnly: true, }), vue(vueConfig), postcss(getPostCSSConfig(config)), babel({ exclude: 'node_modules/**', extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'], babelHelpers: 'bundled', presets: [ [ '@babel/preset-env', { targets: 'last 2 versions and > 2%', }, ], ], }), ...(isWatch ? [] : [ cleaner({ targets: [output.dir], }), ]), ], }; ```
:rollup.config.js
```json5 { "compilerOptions": { "target": "es2019", "strict": true, "lib": [ "DOM", "DOM.Iterable", "ES6" ], "module": "esnext", "moduleResolution": "node", "allowJs": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true, "resolveJsonModule": true, "downlevelIteration": true, "baseUrl": ".", "outDir": "./dist", "sourceMap": true, "declaration": true, "preserveSymlinks": true } } ```
:tsconfig.options.json
```json5 { "extends": "./tsconfig.options.json", "exclude": [ "public", "node_modules", ] } ```
:tsconfig.json
```json5 { "extends": "../../tsconfig.options.json", "include": [ "./src/**/*.vue", "./src/**/*.ts" ], "exclude": ["./dist"], "compilerOptions": { "baseUrl": ".", "jsx": "react", } } ```
:/packages/components/tsconfig.json