facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.22k stars 477 forks source link

Error: Cannot find module 'transform.js' #532

Closed andriyor closed 1 year ago

andriyor commented 1 year ago

Steps to reproduce

npx create-react-app my-app --template redux-typescript

npm i jscodeshift

run.js

(async () => {
    const {run: jscodeshift} = require('jscodeshift/src/Runner')
    const transformPath = 'transform.js';
    const paths = ['src']
    const options = {
        dry: true,
        print: true,
        verbose: 1,
        extensions: 'tsx',
        parser: 'tsx'
    }
    const res = await jscodeshift(transformPath, paths, options)
    console.log(res)
})();

transform.js

module.exports = function(file, api) {
    return api
        .jscodeshift(file.source)
        .findVariableDeclarators("foo")
        .renameTo("bar")
        .toSource();
};

node run.js

Daniel15 commented 1 year ago

Do you have a file called transform.js? It looks like you're trying to use a file called transform.js.

andriyor commented 1 year ago

Just updated description Also, I have no such error inside of the empty project

robert-w-gries commented 1 year ago

I hit a similar error. On windows, I had to run path.resolve(transformPath) to get the tool working:

-    const transformPath = 'transform.js';
+    const transformPath = path.resolve('transform.js');
klippx commented 1 year ago

Same problem here, @robert-w-gries solution fixed it. I would suggest you edit the README, following these instructions that are the first piece of code listed in docs does not work.