-
-
Notifications
You must be signed in to change notification settings - Fork 126
Description
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
- Clone the
metarhia/Example
repository or use an existing clean copy. - Navigate to the project directory:
cd /path/to/Example
- Ensure dependencies are installed:
yarn install
/npm install
- Edit the file
application/bus/worldTime/.service.js
and add aname
property:({ name: 'worldTime', // Add this line url: 'http://worldtimeapi.org/api', limits: [ { calls: 10, per: '1m' }, { calls: 10000, per: '1d' }, ], });
- 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)
...

Additional context
Existing Issues Check
- Search
metarhia/impress
: https://github.com/metarhia/impress/issues?q=is%3Aissue+TypeError+name+bus+service.js - Search
metarhia/Example
: https://github.com/metarhia/Example/issues?q=is%3Aissue+TypeError+name+bus+service.js
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 inimpress/lib/bus.js
(around line 37) andimpress/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 ifexports.name
exists before assigningthis.name = exports.name
fixes the issue, allowing.service.js
files to optionally contain aname
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.