I'm trying to create yeoman generator but I'm unable to get started. I'm following this video on the subject and I can't even get my code to run.
here's my package.json file:
{
"name": "generator-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"yeoman-generator": "^7.1.0"
}
}
and my index.js file:
const Generator = require("yeoman-generator");
module.exports = class extends Generator {
initializing() {
this.log("working!");
}
};
I can run npm link no issues, and when I try to run it I can see it's been hit, but then I get this error:
require() of ES Module ...\generator-test\node_modules\yeoman-generator\dist\index.js from ...\generator-test\generators\app\index.js not supported.
Instead change the require of ...\generator-test\node_modules\yeoman-generator\dist\index.js in ...\generator-test\generators\app\index.js to a dynamic import() which is available in all CommonJS modules.
so I tried that, and ended up with this index.js:
import Generator from "yeoman-generator";
module.exports = class extends Generator {
initializing() {
this.log("working!");
}
};
and this error:
Cannot use import statement outside a module
I'm sure I'm doing something wrong I just don't what it is. Can some one point me in the right direction?
"type": "module"on mypackage.jsonand usingimportinstead ofrequire. But it feels "hacky" to me. Can you elaborate on your suggestion?