developerasun / myCodeBox-web

Open source code box for web developers.
Apache License 2.0
5 stars 0 forks source link

[BUG] Javascript/package: require() of ES Module #267

Closed developerasun closed 2 years ago

developerasun commented 2 years ago

Describe the bug

NPM inquirer package throwing require not support error

To Reproduce Steps to reproduce the behavior:

  1. Go to terminal
  2. Execute node js application with inquirer package(v9.0.0). set package.json like below
{
  "name": "my-cli",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "bin": {
    "@developerasun/create-project": "bin/create-project",
    "create-project": "bin/create-project"
  },
  "publishConfig": {
    "access": "public"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "arg": "^5.0.2",
    "esm": "^3.2.25",
    "inquirer": "^9.0.0"
  },
  "packageManager": "npm@8.5.5"
}
  1. See error

Expected behavior

inquirer executes an interactive terminal question

Screenshots

require-inqurier

Additional context Add any other context about the problem here.

Labeling Add a proper label for the issue

developerasun commented 2 years ago

solution: delete shebang in bin/config file and change it to config.js having package.json set to type module.

before

#!/usr/bin/env node 
require = require("esm")(module/*, options*/)

after

import * as main from "../src/cli.js";

main.cli(process.argv);

Reference

https://github.com/developerasun/myDocumentBox-CS/issues/37