UNPKG

db-migrate-plugin-es6cjs

Version:

db-migrate plugin for accept .cjs files when packaje.json has "type": "module" set

36 lines (17 loc) 903 B
# db-migrate-plugin-es6cjs A plugin to allow CJS migrations. ## Installation npm install db-migrate-plugin-es6cjs ## Implementation Detail The plugin hooks into the functionality of db-migrate itself. In this case it hooks into migrator:migration:hook:require. It allow db-migrate to detect migrations with (.cjs) extensions. ## Why When you have a node project defined as ES6 modules, you got an error when try to import .js files generated by db-migrate tool. ``` [ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Must use import to load ES Module ``` and the solution proposed is: ``` Instead rename 20210102234349-Test.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /..../package.json. ``` but if you rename the file to .cjs as requested, the migration tool can't find, because the it search only for .js files.