Skip to content

Generate command doesn't work if you don't install packages first #159

@NickHeiner

Description

@NickHeiner

I'm running version 3.1.2. I tried two workflows:

  1. Create a new directory.
  2. Run codemod-cli new dir
  3. Run codemod-cli generate codemod c

This will result in an error:

/Users/nheiner/.config/yarn/global/node_modules/yargs/build/index.cjs:2772
                throw err;
                ^

Error: Cannot find module 'codemod-cli'
Require stack:
- /private/tmp/test-codemod/transforms/hoist-require/index.js
- /Users/nheiner/.config/yarn/global/node_modules/codemod-cli/src/transform-support.js
- /Users/nheiner/.config/yarn/global/node_modules/codemod-cli/commands/local/generate/fixture.js
- /Users/nheiner/.config/yarn/global/node_modules/yargs/index.cjs
- /Users/nheiner/.config/yarn/global/node_modules/codemod-cli/bin/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/private/tmp/test-codemod/transforms/hoist-require/index.js:1:23)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/private/tmp/test-codemod/transforms/hoist-require/index.js',
    '/Users/nheiner/.config/yarn/global/node_modules/codemod-cli/src/transform-support.js',
    '/Users/nheiner/.config/yarn/global/node_modules/codemod-cli/commands/local/generate/fixture.js',
    '/Users/nheiner/.config/yarn/global/node_modules/yargs/index.cjs',
    '/Users/nheiner/.config/yarn/global/node_modules/codemod-cli/bin/cli.js'
  ]
}

Running yarn install fixes it. It's a reasonably straightforward fix, but it would be nice if the tool or docs were explicit about this requirement. It's a little surprising that running the same command stops working between steps.

When I did the same steps above, but in an existing monorepo, running generate before installing resulted in no files being written, but the command exited successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions