json-server icon indicating copy to clipboard operation
json-server copied to clipboard

cant find package json-server within node_modules

Open EnergeticPixels opened this issue 1 year ago • 5 comments

PNPM and NPM are reporting that it cannot find json-server from import statement within calling server.js file.

server.js file

import jsonServer from 'json-server';
console.log('Starting JSON Server');

package.json file

{
  "name": "crazy",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "json-server": "^1.0.0-beta.1"
  }
}

The error: ajackman@MarsVenus:~/projects/ep/crazy$ npm run start

[email protected] start node server.js

node:internal/modules/esm/resolve:210 const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified); ^

Error: Cannot find package '/home/ajackman/projects/ep/crazy/node_modules/json-server/package.json' imported from /home/ajackman/projects/ep/crazy/server.js at legacyMainResolve (node:internal/modules/esm/resolve:210:26) at packageResolve (node:internal/modules/esm/resolve:828:14) at moduleResolve (node:internal/modules/esm/resolve:914:18) at defaultResolve (node:internal/modules/esm/resolve:1119:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12) at ModuleLoader.resolve (node:internal/modules/esm/loader:511:25) at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:38) at ModuleJob._link (node:internal/modules/esm/module_job:126:49) { code: 'ERR_MODULE_NOT_FOUND' }

Node.js v22.2.0

npm version 9.5.1 pnpm version 9.1.0 node version 22.2.0

WSL2 / Debian 11 (Guest) / Windows 11 (host)

EnergeticPixels avatar Jun 04 '24 12:06 EnergeticPixels

Same issue as above +1

Bankole2000 avatar Jun 04 '24 22:06 Bankole2000

This issue began with version 1.0 (anything). I walked simple project backwards thru all published packages. The one that worked was version 0.17.4.

On Tue, Jun 4, 2024, 17:30 Bankole @.***> wrote:

Same issue as above +1

— Reply to this email directly, view it on GitHub https://github.com/typicode/json-server/issues/1557#issuecomment-2148515672, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACFHJTBYRQAKRIG5462HH3ZFY5Y5AVCNFSM6AAAAABIYO7K7CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBYGUYTKNRXGI . You are receiving this because you authored the thread.Message ID: @.***>

EnergeticPixels avatar Jun 04 '24 23:06 EnergeticPixels

i think this is because the line:

"main": "./lib/server/index.js",

which used to be in the package.json on 0.17.4 no longer exists on 1.0 versions. which was pointing to the main script, but the 1.0 versions seem to only support the CLI variant.

and thus since this package has become no longer usable like that.

npm install --save-dev [email protected]

should be the fix for now, while asking the maintainers what their plans are surrounding support for running this as express middleware.

quinyx-tjeerd avatar Jun 22 '24 13:06 quinyx-tjeerd

It would be nice if the maintainers had plans to allow it to run as an express middleware. In my case, I need to manipulate some header information that my app expects to see in server call results.

oliveirakennedyjoao avatar Dec 06 '24 13:12 oliveirakennedyjoao

I am having that issue too.

SalahAdDin avatar Feb 09 '25 06:02 SalahAdDin