To find and update all file extensions from .js
to .mjs
in your project, you can use command-line tools like find
and sed
(on Unix-based systems) or PowerShell (on Windows). Here's how you can do it:
Unix-based Systems (Linux, macOS)
Open your terminal and navigate to the root directory of your project. Then run the following command:
bash find . -type f -name '*.js' -exec sh -c 'mv "$1" "${1%.js}.mjs"' _ {} \;
This command finds all files with the .js
extension recursively in the current directory and its subdirectories, then renames them to have the .mjs
extension.
Windows (PowerShell)
Open PowerShell and navigate to the root directory of your project. Then run the following command:
powershell Get-ChildItem -Recurse -Filter "*.js" | Rename-Item -NewName { $_.Name -replace '\.js$', '.mjs' }
This PowerShell command finds all files with the .js
extension recursively in the current directory and its subdirectories, then renames them to have the .mjs
extension.
Note:
- Before performing these operations, make sure to backup your project or use version control (like Git) to track the changes.
- After renaming the files, you might need to update import statements in your code to reflect the new
.mjs
extension.