neovim/node-client

Quickstart example does not work (SyntaxError: Named export 'findNvim' not found. The requested module 'neovim' is a CommonJS module...)

Closed this issue · 2 comments

I tried following the Quickstart example exactly e.g. run npm i neovim in a new empty folder, paste contents of the quickstart example to a demo.mjs file, and run node demo.mjs. Getting the following error:

import { attach, findNvim } from 'neovim'
                 ^^^^^^^^
SyntaxError: Named export 'findNvim' not found. The requested module 'neovim' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'neovim';
const { attach, findNvim } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:120:12)

Node.js v21.6.2

When I tried doing what the error msg suggested e.g.

// import { attach, findNvim } from 'neovim'
import pkg from 'neovim';
const { attach, findNvim } = pkg;

I now get this error:

  const found = findNvim({ orderBy: 'desc', minVersion: '0.9.0' })
                ^

TypeError: findNvim is not a function
    at file:///Users/****/development/sandbox/js/nvim-client/demo.mjs:10:17
    at file:///Users/****/development/sandbox/js/nvim-client/demo.mjs:45:3
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:120:12)

Node.js v21.6.2

Ok, I see that this is because i'm using 4.11.0 and in master findNvim was originally getNvimFromEnv. Quick start example works when I update the import to use getNvimFromEnv instead of findNvim.

I don't see a tag for 4.11.0 though FYI.

Yeah I need to do another release, sorry for the confusion.