Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ESM format output is incorrect & auto detect entry file fails #162

Closed
ShaneYu opened this issue Aug 30, 2024 · 2 comments
Closed

Comments

@ShaneYu
Copy link

ShaneYu commented Aug 30, 2024

Version

System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 4.11 GB / 31.21 GB
  Browsers:
    Edge: Chromium (127.0.2651.86)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @rslib/core: ^0.0.2 => 0.0.2

Details

There are currently two issues I am facing with Rslib at this time.

Rsbuild is meant to be able to automatically find the entry point via src/index.ts and a load of other file extensions, according to the error I get. Issue is that when using Rslib without specifying a source.entry in the config, it cannot locate the entry src/index.ts file that I have.

This results in the following error:

error   Failed to build.
error   Could not find any entry module, please make sure that src/index.(ts|js|tsx|jsx|mjs|cjs) exists,
        or customize entry through the source.entry configuration.

Entry config added to make it work:

source: {
  entry: {
    index: './src/index.ts',
  },
},

Adding in the source.entry config resolves the above issue, then the second issue is that the ESM format output does not look correct. It only outputs *.d.mts file and no actual *.mjs files are created; this means that only type definitions exist and no actual code. Whereas the CJS format is correctly output *.js code files and also the *.d.ts type definition files.

image

Reproduce link

https://github.com/ShaneYu/rslib-esm-issue

Reproduce Steps

To replicate these issues I have created a temp GitHub repository that can be cloned down and played with.

For the second issue regarding ESM format output being incorrect:

  1. Clone the repository with git clone [email protected]:ShaneYu/rslib-esm-issue.git
  2. Install the dependencies with pnpm install
  3. Run a build with pnpm build

Now go and look at the output files under ./dist/esm you will notice that no *.mjs code files have been created, however the *.mts type definition files have been. The CJS output on the other hand, this has the expected code files and type definitions.

image

For the first issue regarding the entry point configuration:

Skip steps 1 and 2 if done previously.

  1. Clone the repository with git clone [email protected]:ShaneYu/rslib-esm-issue.git

  2. Install the dependencies with pnpm install

  3. Edit the rslib.config.ts file to remove the source.entry config from both ESM and CJS lib configs

    source: {
      entry: {
        index: './src/index.ts',
      },
    },
  4. Run a build with pnpm build

Notice that despite having a src/index.ts file, it results in an error and states that the entry file cannot be found.

image

@ShaneYu ShaneYu changed the title [Bug]: [Bug]: ESM format output is incorrect & auto detect entry file fails Aug 30, 2024
@Timeless0911
Copy link
Contributor

Can you upgrade @rslib/core to 0.0.4, I think the two issues have been solved.

@ShaneYu
Copy link
Author

ShaneYu commented Sep 2, 2024

@Timeless0911 Thank you, I can confirm that upgrading to 0.0.4 has indeed resolved both issues. 😁

❤️ Thank you! 😄 Loving rslib so much! 😉

@ShaneYu ShaneYu closed this as completed Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants