针对不同的NODE_MODULE_VERSION编译-树型解析器,ATOM软件包

问题描述

我创建了一个tree-sitter解析器,该解析器正在解析我们使用的一些旧式SAP语言,以使程序包与ATOM兼容。 我会非常有素养,因为我对自己搞砸的地方不太自信。

根据tree-sitter文档,我阅读了许多指南-我已完成以下操作:

已将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'将创建的树保存器解析器发布到了npm:

我从ATOMs Generate package函数创建了一个程序包,在程序包中创建了一个“语法”目录,并创建了一个具有以下值的.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)。 在很多尝试使用“电子重建”进行重新编译之后,我一直停留在这里,但我没有成功,因此我决定需要更多有经验的助手。

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

解决方法

我设法解决了这个问题。 显然,您应该:

npm install --save-dev electron@6.1.12 (the current electron version atom was using at the time)
npm install --save-dev electron-rebuild 

electron-rebuild --version 6.1.12 (the current electron version atom was using at the time)

如果仍然抱怨您运行的是其他版本,则应该:

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

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