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 a name 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
Check result: No similar open Issues were found at the time of our research
Additional context
- The issue occurs specifically in
impress@3.0.16 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.
Impress and Node.js versions
impress: 3.0.16 ; node v20.18.1
Platform
macOS 15.3.1 24D70
Describe the bug
When
impressloads code from theapplication/bus/directory, specifically processing.service.jsfiles, it attempts to assign anameproperty to the loaded function or object. If the exported object from the.service.jsfile already explicitly defines anameproperty, this assignment fails with aTypeError: Cannot assign to read only property 'name' of function ...because thenameproperty of functions/objects is often read-only in JavaScript. This prevents the application from starting correctly in the affected worker processes.To Reproduce
metarhia/Examplerepository or use an existing clean copy.cd /path/to/Exampleyarn install/npm installapplication/bus/worldTime/.service.jsand add anameproperty:yarn test/npm testExpected behavior
The application should start without errors in all worker processes, regardless of whether a
.service.jsfile contains an optionalnameproperty. Theimpressloader should either ignore the existingnameproperty or handle the assignment safely.Screenshots
The application fails to start correctly in worker processes. The following
TypeErroris logged for each worker during the loading phase:Additional context
Existing Issues Check
metarhia/impress: https://github.com/metarhia/impress/issues?q=is%3Aissue+TypeError+name+bus+service.jsmetarhia/Example: https://github.com/metarhia/Example/issues?q=is%3Aissue+TypeError+name+bus+service.jsCheck result: No similar open Issues were found at the time of our research
Additional context
impress@3.0.16due to the logic inimpress/lib/bus.js(around line 37) andimpress/lib/code.js(around line 75) when handling.service.jsfiles.nameproperty from the.service.jsfile works around the issue.impress/lib/code.jsto check ifexports.nameexists before assigningthis.name = exports.namefixes the issue, allowing.service.jsfiles to optionally contain anameproperty without causing a TypeError.nameproperty in.service.jsis not required by the Metarhia, as the service name is typically derived from the directory name.