vadimdemedes / ink

🌈 React for interactive command-line apps
https://term.ink
MIT License
27.13k stars 608 forks source link

ERR_REQUIRE_ESM error with create-ink-app #575

Closed george-vlahakis closed 1 year ago

george-vlahakis commented 1 year ago

Following out of the box instructions (from main page):

npx create-ink-app my-ink-cli

And running via:

node cli

Produces:

/my-ink/cli.js:4
const importJsx = require('import-jsx');
                  ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /my-ink/node_modules/import-jsx/index.js from /my-ink/cli.js not supported.
Instead change the require of index.js in /my-ink/cli.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/my-ink/cli.js:4:19) {
  code: 'ERR_REQUIRE_ESM'
}
vadimdemedes commented 1 year ago

I just released an update to create-ink-app in https://github.com/vadimdemedes/create-ink-app/pull/28. If you upgrade to the latest version, you shouldn't see this issue anymore. Thanks for reporting!

george-vlahakis commented 1 year ago

Following the instructions in generated readme.md we still get the same error.

> ink
ink/cli.js:4
const importJsx = require('import-jsx');
                  ^

Error [ERR_REQUIRE_ESM]: require() of ES Module ink/node_modules/import-jsx/index.js from ink/cli.js not supported.
Instead change the require of index.js in ink/cli.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (ink/cli.js:4:19) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.15.0

If there are further instructions on how to go about upgrading the create-ink-app would much appreciate it. The cli.js still has require vs import. Apologies if the question sounds dumb.

vadimdemedes commented 1 year ago

It doesn't look like you installed the latest version of create-ink-app. This should work:

npm install --global create-ink-app@latest
create-ink-app my-cli
my-cli
george-vlahakis commented 1 year ago

As per your instructions the following error:

> create-ink-app my-ink

  ❯ Copy files
    ✖ Common files
      → Cannot copy `/usr/local/lib/node_modules/create-ink-app/templates/_common/.gitignore`: the file doesn't exist
      JavaScript files
    Install dependencies
    Format code
    Build
    Link executable
NestedError: Cannot copy `/usr/local/lib/node_modules/create-ink-app/templates/_common/.gitignore`: the file doesn't exist
    at file:///usr/local/lib/node_modules/create-ink-app/node_modules/cpy/index.js:198:11
    at cpy (file:///usr/local/lib/node_modules/create-ink-app/node_modules/cpy/index.js:284:4)
    at Task.task (file:///usr/local/lib/node_modules/create-ink-app/index.js:74:10)
    at /usr/local/lib/node_modules/create-ink-app/node_modules/listr/lib/task.js:167:30

Same applies for local install.

Do not wish to be a pain, just reporting as I see it.

ChrisSchofieldCheckatrade commented 1 year ago

I am also experiencing the above issue.

vadimdemedes commented 1 year ago

You were right, create-ink-app on npm was missing dot files. I released https://github.com/vadimdemedes/create-ink-app/releases/tag/v3.0.1 with a fix. When you update, you shouldn't see this error anymore.

george-vlahakis commented 1 year ago

Reporting against latest instructions:

[george@:~/Desktop/my-ink-app]:>npx create-ink-app my-ink

  ✔ Copy files
  ✔ Install dependencies
  ✔ Format code
  ✔ Build
  ↓ Link executable [skipped]
    → `npm link` failed, try running it yourself

  Ink app created in my-ink:
    $ cd my-ink

  Build:
    $ npm run build

  Watch and rebuild:
    $ npm run dev

  Run:
    $ my-ink

[george@:~/Desktop/my-ink-app]:>cd my-ink 
[george@:~/Desktop/my-ink-app/my-ink]:>npm run build

> my-ink@0.0.0 build
> babel --out-dir=dist source

Successfully compiled 2 files with Babel (291ms).
[george@:~/Desktop/my-ink-app/my-ink]:>my-ink
zsh: command not found: my-ink
[george@:~/Desktop/my-ink-app/my-ink]:>sudo npm link

changed 1 package, and audited 3 packages in 413ms

found 0 vulnerabilities
[george@:~/Desktop/my-ink-app/my-ink]:>my-ink
zsh: permission denied: my-ink
[george@:~/Desktop/my-ink-app/my-ink]:>sudo my-ink 
sudo: my-ink: command not found
[george@:~/Desktop/my-ink-app/my-ink]:>npm run dev

> my-ink@0.0.0 dev
> babel --out-dir=dist --watch source

Successfully compiled 2 files with Babel (283ms).
The watcher is ready.

^C
[george@:~/Desktop/my-ink-app/my-ink]:>npm run test

> my-ink@0.0.0 test
> prettier --check . && xo && ava

Checking formatting...
All matched files use Prettier code style!

  ✔ greet unknown user
  ✔ greet user with a name
  ─

  2 tests passed

Something is still no quite right. Maybe the instructions need updating, but I see no immediate clear instructions on how to run the test app.

vadimdemedes commented 1 year ago

Not sure why it's failing for you, could be related to your Node.js/npm setup. It runs fine for me with the latest create-ink-app:

https://user-images.githubusercontent.com/697676/230948541-3d88073e-373b-4165-9f0c-33eee64b25d1.mp4

george-vlahakis commented 1 year ago

For others as a reference:

I installed NodeJS on my Mac using the installer found on their site https://nodejs.org/en/download This seems to have installed parts of it as sudo and caused various issues.

Completely wiped that installation and re-installed with brew:

brew install node

There on all issues got resolved.