chiubaka / genesis

Creates standardized monorepos and pre-configured project scaffolding for Chiubaka Technologies projects.
2 stars 0 forks source link

Generated workspaces / projects fail commit with lint:staged hook due to `prettier` error #137

Closed chiubaka closed 2 years ago

chiubaka commented 2 years ago
✖ prettier --write:
node:internal/modules/cjs/loader:958
  throw err;
  ^

Error: Cannot find module './package.json'
Require stack:
- /Users/dchiu/Developer/genesis-sample-2/node_modules/.bin/prettier
    at Module._resolveFilename (node:internal/modules/cjs/loader:955:15)
    at Module._load (node:internal/modules/cjs/loader:803:27)
    at Module.require (node:internal/modules/cjs/loader:1021:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/dchiu/Developer/genesis-sample-2/node_modules/.bin/prettier:59:19)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/dchiu/Developer/genesis-sample-2/node_modules/.bin/prettier'
  ]
}
chiubaka commented 2 years ago

Very odd error. Noticing this on lib.node and app.react.

chiubaka commented 2 years ago

Inside the actual prettier bin there's this:

var pleaseUpgradeNode = require_please_upgrade_node();
var packageJson = require("./package.json");
pleaseUpgradeNode(packageJson);
var cli = require("./cli.js");
module.exports = cli.run(process.argv.slice(2));

The problem seems to be with the require("./package.json") line here. Printing cwd shows the right directory, though... so this is a bit weird.

chiubaka commented 2 years ago

require("./package.json") in a simple testnode script does work, though 🤔. Removing changes to package.json from the stage doesn't solve the problem. Nor does throwing away changes to package.json.

I think to solve this I'm going to need to do some kind of bisect, unfortunately.

chiubaka commented 2 years ago

Hm. Providing an absolute path to a package.json file results in a working require. So something about the relative pathing and the current working directory for resolution??

chiubaka commented 2 years ago

I attempted to upgrade Prettier in case that changes anything. It didn't.

chiubaka commented 2 years ago

Coming back to this after the long weekend and, oddly, this isn't happening on a fresh workspace with generated React app anymore.

Best I can come up with is that a restart of my computer has somehow changed something? That or I'm being very sure to use the local registry this time by using npm_config_registry=http://localhost:4873 npx genesis.

Either way... seems like this is fixed??