Skip to content

TypeError when loading bus/.service.js file containing a 'name' property #1979

@scodeit

Description

@scodeit

Impress and Node.js versions

impress: 3.0.16 ; node v20.18.1

Platform

macOS 15.3.1 24D70

Describe the bug

When impress loads code from the application/bus/ directory, specifically processing .service.js files, it attempts to assign a name property to the loaded function or object. If the exported object from the .service.js file already explicitly defines a name property, this assignment fails with a TypeError: Cannot assign to read only property 'name' of function ... because the name property of functions/objects is often read-only in JavaScript. This prevents the application from starting correctly in the affected worker processes.

To Reproduce

  1. Clone the metarhia/Example repository or use an existing clean copy.
  2. Navigate to the project directory: cd /path/to/Example
  3. Ensure dependencies are installed: yarn install / npm install
  4. Edit the file application/bus/worldTime/.service.js and add a name property:
    ({
      name: 'worldTime', // Add this line
      url: 'http://worldtimeapi.org/api',
      limits: [
        { calls: 10, per: '1m' },
        { calls: 10000, per: '1d' },
      ],
    });
  5. Run the tests, which initialize the application: yarn test / npm test

Expected behavior

The application should start without errors in all worker processes, regardless of whether a .service.js file contains an optional name property. The impress loader should either ignore the existing name property or handle the assignment safely.

Screenshots

The application fails to start correctly in worker processes. The following TypeError is logged for each worker during the loading phase:


 03:26:56  W1   error   TypeError: Cannot assign to read only property 'name' of function 'async (args) => { ... }'
   Function.assign (<anonymous>)
   Object.prepare (/node_modules/impress/lib/bus.js:37:17)
   Code.change (/node_modules/impress/lib/code.js:75:40)
   async Code.load (/node_modules/impress/lib/place.js:22:14)
   ...
Image

Additional context

Existing Issues Check

Check result: No similar open Issues were found at the time of our research

Additional context

  • The issue occurs specifically in [email protected] due to the logic in impress/lib/bus.js (around line 37) and impress/lib/code.js (around line 75) when handling .service.js files.
  • Removing the name property from the .service.js file works around the issue.
  • Applying a patch to impress/lib/code.js to check if exports.name exists before assigning this.name = exports.name fixes the issue, allowing .service.js files to optionally contain a name property without causing a TypeError.
  • The name property in .service.js is not required by the Metarhia, as the service name is typically derived from the directory name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions