【问题标题】:Compiled against different NODE_MODULE_VERSION - Tree-sitter parser, ATOM package针对不同的 NODE_MODULE_VERSION 编译 - Tree-sitter 解析器,ATOM 包
【发布时间】:2021-02-05 08:04:30
【问题描述】:

我创建了一个 tree-sitter 解析器,它解析我们使用的一些遗留 SAP 语言,以使包与 ATOM 兼容。 我会非常了解我所采取的行动,因为我对自己搞砸的地方不太自信。

根据我阅读的许多指南,我已经完成了以下操作:

将 D:\path-to-project\node_modules.bin 添加到 PATH

npm install -g node-gyp (I have installed the dependencies - MSVC 2017 and Python 2.7)

创建了一个新目录并 cd 到它:

npm init (followed the dialog)
npm install
npm install --save-dev nan
npm install --save-dev tree-sitter-cli

现在我们可以创建我们的 tree-sitter grammar.js 文件并生成 tree-sitter 解析器,我这样做了:

创建了grammar.js并写下了必要的语法 打开 CMD,cd 到项目文件夹,然后:

tree-sitter generate
node-gyp configure
node-gyp build
tree-sitter test (To check if the parser is working correctly, which it does)

因此,现在我可以将解析器集成到 ATOM 包中。 所以我通过 - 'npm publish' 将我创建的 tree-sitter 解析器发布到了 npm:

我从 ATOM 生成包函数创建了一个包,在包中创建了一个“语法”目录和一个具有以下值的 .cson 文件:

name: 'Human readable name'
scopeName: 'A unique, stable identifier for the language.'
type: 'tree-sitter' (indicates that we are using tree-sitter grammar not TextMate one)
parser: 'Here we must the npm package name that we published to NPM' 
fileTypes: ['array of file extensions that the package will run on for example 'cpp'']

这就是有趣的地方。在我的 ATOM 包目录中执行“npm install my-npm-package-name”后,我在 ATOM 中收到错误:

The module '\\?\D:\Users\myUser\github\my-ATOM-package-name\node_modules\my-tree-sitter-npm-package    
\build\Release\my-tree-sitter-npm-package_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 73. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`). 
in D:\Users\myUser\.atom\packages\my-ATOM-package-name\grammars\the-cson-file-mentioned.cson

根据我所做的网络调查,这是因为 ATOM 使用的 NodeJs 版本与我使用的不同(NodeJs v 12.4.0)。 这就是我坚持的地方,在多次尝试使用“electron-rebuild”重新编译之后,我放弃了但没有成功,并决定我需要更有经验的帮助者。

我正在 Windows 上开发和安装。 NodeJS 与 nvm 一起安装,我正在使用 v12.4.0 进行开发。

【问题讨论】:

    标签: node.js electron node-modules atom-editor treesitter


    【解决方案1】:

    我设法解决了这个问题。 显然或不那么明显,您应该:

    npm install --save-dev electron@9.3.5 (the current electron version atom was at the time of the last edit of the answer)
    npm install --save-dev electron-rebuild 
    
    electron-rebuild --version 9.3.5 (the current electron version atom was using at the time of the last edit of the answer)
    

    如果它仍然抱怨你正在运行不同的版本,你应该:

    node-gyp rebuild
    electron-rebuild --version 9.3.5 (the current electron version atom was using at the time)
    

    在发布到 npm 之前: 删除 binding.gyp、package-lock.json 文件和 Electron 二进制文件夹

    【讨论】:

      猜你喜欢
      • 2020-09-04
      • 1970-01-01
      • 2019-12-03
      • 2020-12-22
      • 2018-03-05
      • 2019-07-01
      • 2022-01-06
      • 2021-04-18
      相关资源
      最近更新 更多