-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Troubleshooting
My reproducible example - https://github.com/lavcraft/rollup-typescript-project-references-example-problems
You need
- clone
- npm run ci
Follow to next instructions
- Does
tsc
have the same output? If so, please explain why this is incorrect behavior
Run npm run -w @project/sdk build
- tsc variant works fine and generate d.ts files into correct directories
- Does your Rollup plugin order match this plugin's compatibility? If not, please elaborate
I guess order is correct:
nodeResolve(),
typescript2()
- Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction
My example - https://github.com/lavcraft/rollup-typescript-project-references-example-problems
Follow to README or read next lines:
Two commands for feel difference between tsc and rollup in my case:
TSC baseline
npm run -w @project/sdk build
- tsc variant- And see d.ts files in dirs
tree packages/sdk/build
packages/sdk/build
├── actions
│ ├── create.d.ts
│ ├── create.d.ts.map
│ └── create.js
├── models
│ ├── user.d.ts
│ ├── user.d.ts.map
│ └── user.js
└── tsconfig.tsbuildinfo
All d.ts files existed in right location (except d.ts from project from project reference, but it is ok for tsc i guess)
Rollup variant
rm -rf packages/sdk/build && npm run -w @project/sdk rollup
- And see d.ts files in dirs
tree packages/sdk/build
packages/sdk/build
├── actions
│ ├── create.js
│ └── create.js.map
├── models
│ ├── user.js
│ └── user.js.map
├── sdk <------------------------ THIS DIR SUSPICIOUS
│ └── src
│ ├── actions
│ │ ├── create.d.ts
│ │ └── create.d.ts.map
│ └── models
│ ├── user.d.ts
│ └── user.d.ts.map
└── shared <------------------------ THIS DIR SUSPICIOUS
└── src
└── test
├── util.d.ts
└── util.d.ts.map
Created to excess directories with typings - sdk and shared
Please help me to explain right behaviour or workaround. Because my next step is apply dts plugin for obtain valid d.ts files without internal paths. But some difficulties happened when all this d.ts located in strange directories :)
Environment
Versions
System:
OS: macOS 13.3.1
CPU: (8) arm64 Apple M1 Pro
Memory: 52.64 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
pnpm: 8.6.1 - /opt/homebrew/bin/pnpm
npmPackages:
typescript: ^5.1.5 => 5.1.5
rollup.config.js
:
rollup.config.js
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import typescript2 from 'rollup-plugin-typescript2';
import fs from 'fs';
import path from 'path';
import * as url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: {
...files('actions'),
...files('models'),
},
output: {
sourcemap: true,
dir: 'build',
preserveModules: false,
format: 'esm'
},
plugins: [
nodeResolve(),
typescript2({
// build: true,
// useTsconfigDeclarationDir: true,
// declarationDir: './types',
}),
// commonjs(),
],
external: [
'undici',
'querystring',
'mobx',
'mobx-react-lite',
'mobx-utils',
'react',
],
watch: {
chokidar: true,
exclude: ['build/**', '**/*.d.ts', '**/*.js']
}
};
function files(dir = '.', exclude = ['__tests__']) {
return fs
.readdirSync(path.resolve(__dirname, `src/${dir}`))
.reduce((prev, current) => {
if (exclude.includes(current)) return prev;
const targetName = current.replace('.ts', '');
prev[`${dir}/${targetName}`] = `./src/${dir}/${current}`;
return prev;
}, {});
}
export default [config];