ts-migrate icon indicating copy to clipboard operation
ts-migrate copied to clipboard

How to migrate require -> import and module.exports -> export default

Open rysi3k opened this issue 5 years ago • 8 comments

Hello I have tried to use this package, but I have problem with auto migrate require to import and exports to export default. Now when I ran npx ts-migrate-full it leaves me many lines:

// @ts-expect-error ts-migrate(2451) FIXME: Cannot redeclare block-scoped variable 'validation... Remove this comment to see the full error message
const validation = require('express-validation');

IMHO it should be migrated to import lines. Maybe I'm missing something? Or I should migrate it manually first?

Regards Tomasz

rysi3k avatar Oct 29 '20 09:10 rysi3k

Hello I have tried to use this package, but I have problem with auto migrate require to import and exports to export default. Now when I ran npx ts-migrate-full it leaves me many lines:

// @ts-expect-error ts-migrate(2451) FIXME: Cannot redeclare block-scoped variable 'validation... Remove this comment to see the full error message
const validation = require('express-validation');

IMHO it should be migrated to import lines. Maybe I'm missing something? Or I should migrate it manually first?

Regards Tomasz

try this -> import * as validation from "express-validation"

bineetNaidu avatar Oct 31 '20 06:10 bineetNaidu

try this -> import * as validation from "express-validation"

I have no problem with fix this issue, but I'm wondering what prevents ts-migrate from migrate require -> import and module.exports -> export default ? I have almost 100 files, with many imports in each file, fixing it manually is horrible job...

rysi3k avatar Nov 02 '20 08:11 rysi3k

It's just what it is :smile: (ES6 Syntax).. If You need any help you can always ask. Iam Ready to help.

bineetNaidu avatar Nov 02 '20 08:11 bineetNaidu

I agree that it would be neat if ts-migrate handled CJS to ESM migration. However, in the meantime, there are other standalone codemods you can use for that.

NickHeiner avatar Jan 26 '21 23:01 NickHeiner

Hey @NickHeiner which codemod are You suggesting?

rysi3k avatar Jan 27 '21 08:01 rysi3k

I'm not suggesting one in particular. Just google for it. :smile:

NickHeiner avatar Jan 31 '21 15:01 NickHeiner

@rysi3k any solution to this?

fpereira1 avatar Apr 12 '21 00:04 fpereira1

This seems to be the main one and it's working well. https://github.com/5to6/5to6-codemod

fpereira1 avatar Apr 12 '21 00:04 fpereira1