Skip to content

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

@colinaaa

Description

@colinaaa

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)

Metadata

Metadata

Assignees

Labels

🐞 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions