question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

3reactions
fpereira1commented, Apr 12, 2021

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

2reactions
rysi3kcommented, Nov 2, 2020

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

module.exports vs. export default in Node.js and ES6
We can import the module in two ways: Either using CommonJS or using ES6 import syntax. Your issue: I believe you are doing...
Read more >
Node Module Exports Explained – With JavaScript ...
Default exporting in a Node.js module is as simple as this: ... Node.js modules can import by require -ing the exported value.
Read more >
export - JavaScript - MDN Web Docs
Every module can have two different types of export, named export and default export. You can have multiple named exports per module but...
Read more >
Module Exports vs. Export Default: Why Not Both?
Simplify usage: Having a default export simplifies import when the person importing the module just wants the obvious thing from there. · Signal ......
Read more >
ES6 Modules and How to Use Import and Export in ...
You can also give an aliases to exported members with the as keyword: ; You can define a default export with the default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found