-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Error: Cannot find module 'utils' when executing local transform #146
Comments
Hey @EliteUser, thanks for raising an issue! Having a look at the code now and noticed // src/3.0.0/transform.ts
-import { applyMotions } from 'utils';
+import { applyMotions } from '../../utils'; // src/3.0.0/motions/test-motion/test-motion.ts
-import { renameImportSpecifier } from 'utils';
+import { renameImportSpecifier } from '../../../../utils'; I think you might be expecting this to work via webpack's import alias which isn't setup in this particular repo. To replicate it here, you will have to setup webpack, however IMO the simple relative import approach is best.
This is a strange one, this should be working given it passes the transform directly to Here's a link to a working repro: https://stackblitz.com/edit/node-cufcnk?file=src/3.0.0/motions/test-motion/test-motion.ts Cheers, |
Hello thank you for the answer! |
Oohh now I understand, this is actually because One way you can work around this is to transpile your TS files into javascript, similar to what we do with more typical web applications. For example:
For what it's worth, All you need to do is run:
Optionally you can then run the following to create a transform automatically 😄
|
That being said, I think the |
Adding my stone. Given the following:
module.exports = {
maintainers: [],
targets: [],
description: '',
transforms: {
'legacy-avatar': require.resolve('./dist/legacy-avatar'),
'legacy-checkbox': require.resolve('./dist/legacy-checkbox'),
'legacy-icon': require.resolve('./dist/legacy-icon'),
},
presets: {},
}; This command fails: ❯ pwd
/Users/xxxxx/Dev/search/packages/codemods
❯ codeshift -t ./dist/legacy-checkbox/index.js ../shared/components/MyFile.js -p babel
Running transform: ./dist/legacy-checkbox/index.js
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module './dist/legacy-checkbox/index.js'
Require stack:
- /Users/xxxxx/.config/yarn/global/node_modules/jscodeshift/src/Worker.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at setup (/Users/xxxxx/.config/yarn/global/node_modules/jscodeshift/src/Worker.js:91:18)
at Object.<anonymous> (/Users/xxxxx/.config/yarn/global/node_modules/jscodeshift/src/Worker.js:45:3)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/xxxxx/.config/yarn/global/node_modules/jscodeshift/src/Worker.js'
]
}
Node.js v18.12.1
All done.
Results:
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 0.257seconds While this succeeds:
|
Hello, trying to use your codeshift-cli, but faced a problem.
I created an example of my codemode repo - https://stackblitz.com/edit/node-uhcfpx?file=index.ts
Here I have a
src
folder which contains all version transforms. Each has its ownmotions
and so on. Also there is autils
folder with some functions I need across all transformations.So I'm trying to execute local transform, but getting some errors:
codeshift -t ./src/3.0.0/transform.ts ./tmp/foo.tsx
- getting anError: Cannot find module './src/3.0.0/transform.ts'
. Looks like cli cannot find a transform file for some reason. Maybe I'm doing something wrong.codeshift ./tmp/foo.tsx
- it says that "No transforms specified" but then it gives me a prompt where I can choose a transformation (3.0.0) and then it throws anError: Cannot find module 'utils'
. In my project I have a utils folder and I use it in my transformations, but for some reason cli can not resolve it.jest
in console is ok)Could you please help me to understand and find a problem?
The text was updated successfully, but these errors were encountered: