metarhia / impress

Enterprise application server for Node.js and Metarhia private cloud ⚡
https://metarhia.com
MIT License
966 stars 128 forks source link

Cannot set property x of #<Object> which has only a getter #1938

Open DmitryScaletta opened 10 months ago

DmitryScaletta commented 10 months ago

Impress and Node.js versions

impress: 3.0.13, node: v21.1.0

Platform

No response

Describe the bug

drizzle-orm@0.29.0

First the module loader loads the main package which imports a relations module which exports a relations function.

node_modules/drizzle-orm/index.cjs https://github.com/drizzle-team/drizzle-orm/blob/0d833d1ca78735e29b124e2a672bda2c85738f48/drizzle-orm/src/index.ts#L10 ![image](https://github.com/metarhia/impress/assets/5096735/7eeebe18-c16c-4817-af2d-8cdb59d3f73a)
node_modules/drizzle-orm/relations.cjs https://github.com/drizzle-team/drizzle-orm/blob/0d833d1ca78735e29b124e2a672bda2c85738f48/drizzle-orm/src/relations.ts#L495 ![image](https://github.com/metarhia/impress/assets/5096735/3dbbdb1b-75b0-4dbe-9c90-12b7fb5c7dd3)

Then it tries to load a relations submodule (the same name as the function that was already loaded).

node_modules/drizzle-orm/package.json ![image](https://github.com/metarhia/impress/assets/5096735/79cee473-d124-43cc-ac52-6c934f6fa543)

So lib[subName] is already exists and it points to the same object as sub.relations.

I added this debug code here:

https://github.com/metarhia/impress/blob/4cabe81e1cef6870a10d7c7b020f8618db3bdbf3/lib/deps.js#L57-L58

const sub = appRequire(name + '/' + subName);
if (name === 'drizzle-orm' && subName === 'relations') {
  console.log(lib[subName] && (lib[subName] === sub[subName])); // true
}
lib[subName] = sub; // the error is here
TypeError: Cannot set property relations of #<Object> which has only a getter
    at loadModule (node_modules\impress\lib\deps.js:63:24)
    at Object.<anonymous> (node_modules\impress\lib\deps.js:89:13)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (node_modules\impress\lib\planner.js:3:32)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)

sql submodule is also have this problem.

To Reproduce

  1. Run npm i drizzle-orm@0.29.0
  2. Run npm start
  3. See a module loading error

Expected behavior

No response

Screenshots

No response

Additional context

All drizzle-orm's transpiled code can be found here: https://www.npmjs.com/package/drizzle-orm?activeTab=code