weiran-zsd / dts-cli

Zero-config CLI for TypeScript package development
MIT License
440 stars 23 forks source link

Scaffolded project does not build out of the box with README customization recommendations #211

Closed SirSKillz closed 4 months ago

SirSKillz commented 6 months ago

Current Behavior

After using npx dts-cli create test[1-3] with all cases (basic, react, react with storybook), I noticed that react with storybook does not build at all out of the box (#212), and none of them will build after adding the dts.config.ts file from the configuration section with this error:

Error: Cannot find module 'dts-cli'
Require stack:
- C:\Users\_\repos\test1\dts.config.ts
- C:\Users\_\repos\test1\node_modules\dts-cli\dist\createBuildConfigs.js
- C:\Users\_\repos\test1\node_modules\dts-cli\dist\index.js

    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (C:\Users\_\repos\test1\node_modules\@cspotcode\source-map-support\source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:901:27)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (C:\Users\_\repos\test1\dts.config.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module.m._compile (C:\Users\_\repos\test1\node_modules\ts-node\src\index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Object.require.extensions.<computed> [as .ts] (C:\Users\_\repos\test1\node_modules\ts-node\src\index.ts:1621:12)

Here is the original dts.config.ts file:

import { defineConfig } from 'dts-cli';

export default defineConfig({
  // This function will run for each entry/format/env combination
  rollup: (config, options) => {
    return config; // always return a config.
  },
});

After adjusting the dts.config.ts file from export default defineConfig({...}) to module.exports = defineConfig({...}), the same error occurs. Finally, changing the syntax to module.exports = {...} allows all 3 to build properly (react with storybook needed some other changes in tsconfig.json first [#212]).

Expected behavior

Ideally: Any of these methods of exporting should work correctly At least: It should be made clear that only module.exports = {...} will function

Suggested solution(s)

Presumably this is an issue with the code that merges these files, or maybe defineConfig itself. I assume adjusting one of these would allow it to handle different export methods

Additional context

None

Your environment

System:
    OS: Windows 10 10.0.19045
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 18.75 GB / 31.91 GB
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 121.0.6167.187
    Edge: Chromium (121.0.2277.128)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    dts-cli: ^2.0.4 => 2.0.4
    typescript: ^5.3.3 => 5.3.3
OlegWock commented 4 months ago

Adding

"main": "./dist/index.js",

into node_modules/dts-cli/package.json (either by maintainer or by using patch-package) should solve this and #207