Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant find package json-server within node_modules #1557

Open
EnergeticPixels opened this issue Jun 4, 2024 · 3 comments
Open

cant find package json-server within node_modules #1557

EnergeticPixels opened this issue Jun 4, 2024 · 3 comments

Comments

@EnergeticPixels
Copy link

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

crazy@1.0.0 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)

@Bankole2000
Copy link

Same issue as above +1

@EnergeticPixels
Copy link
Author

EnergeticPixels commented Jun 4, 2024 via email

@quinyx-tjeerd
Copy link

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 json-server@0.17.4

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants