0

When try to change the extension to .ts on all .js files in app/admin folder using this command

renamer --find '.js' --replace '.ts' 'app/admin/**/*.js'

I got this error

/usr/lib/node_modules/renamer/bin/cli.mjs:2
import CliApp from '../lib/cli-app.mjs'
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:160:9)

before running this command run:

npm i -g renamer

I want to convert those js files to ts files because try to migrate an AngularJS application to Angular12. If you know any solution for this error please tell me.

  • What version of node.js are you running? This error is indicative that you are using a version of node.js that doesn't support ESM (ECMAScript Modules) - see [this answer](https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import?%3Fr=SearchResults). Running: `npm view renamer engines.node` reveals that the latest`renamer` needs node.js version `>=14`. Either update node.js or try installing an earlier version of `renamer`. – RobC Jun 10 '21 at 12:18

0 Answers0