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]: Module is empty when it is another entry module #452

Open
colinaaa opened this issue Nov 19, 2024 · 2 comments
Open

[Bug]: Module is empty when it is another entry module #452

colinaaa opened this issue Nov 19, 2024 · 2 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@colinaaa
Copy link

colinaaa commented Nov 19, 2024

Version

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 14.12 GB / 96.00 GB
    Shell: 3.7.1 - /opt/homebrew/bin/fish
  Browsers:
    Chrome: 130.0.6723.117
    Safari: 17.6
  npmPackages:
    @rslib/core: ^0.0.18 => 0.0.18

Details

I'm building an library using Rslib with multiple entries:

import { defineConfig } from '@rslib/core';

export default defineConfig({
  lib: [
    {
      format: 'esm',
      syntax: 'es2021',
    },
  ],
  source: {
    entry: {
      index: './src/index.ts',
      foo: './src/foo.ts',
    },
  },
});

And index is using foo as dependencies:

// index.js
import { foo } from './foo.js'
console.log(foo)

But this results in get an empty module ./src/foo.ts in dist/index.js:

// dist/index.js
var __webpack_modules__ = {
    "./src/foo.ts": function() {}
};

which would cause error at runtime.

Reproduce link

https://github.com/colinaaa-reproductions/rslib-repro-multi-entries

Reproduce Steps

  1. pnpm install
  2. pnpm build
  3. node dist/index.js

An error occurs:

console.log((0, foo.foo)());
                        ^

TypeError: (0 , foo.foo) is not a function
    at /root/dist/index.js:22:25
    at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
@colinaaa colinaaa added the 🐞 bug Something isn't working label Nov 19, 2024
@fi3ework
Copy link
Member

fi3ework commented Nov 19, 2024

Do you expect foo is shared between dist/foo.js and dist/index.js?

Sharing modules could break ESM and it's a known issue. We might support non-sharing mode (like turn off https://esbuild.github.io/api/#splitting in esbuild) in short time to make sure the output is correct at least.


Also ref multiple entries issue #316.

@fi3ework fi3ework self-assigned this Nov 19, 2024
@colinaaa
Copy link
Author

Do you expect foo is shared between dist/foo.js and dist/index.js?

For now, no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants