node.js打包exe可执行文件遇到的问题记录

1.buffer.js ,three.js 这样引用会报错:

 import { Buffer } from 'buffer';
 import * as THREE from 'three';

所以需要找到node_modules里相关js文件,然后引用其文件路径(我是复制出来放到src文件夹下了),原因不明:

import * as All from './src/buffer.js';

import * as THREE from "./three.module.js";

2.使用 pkg 打包时报错:

Warning Failed to make bytecode...

这个时候,就要用ncc打包工具,把node项目,先打包成单个的js文件,然后再用pkg打包

ncc build input.js -o dist

3.使用 pkg 打包ncc转换后的js文件时报错:

import.meta may appear only with 'sourceType: "module"'

解决办法是,打开转换后的js文件,把引用了import.meta的那行代码删掉

4.一些经验

使用process.argv获取输入参数

使用process.stdout.write进行标准化输出

使用 pkg命令打包

pkg -t win ./dist/index.js

 

参考文献:

https://discourse.threejs.org/t/error-relative-references-must-start-with-either-or/13573

https://blog.oioweb.cn/139.html

https://zhuanlan.zhihu.com/p/151447683

 

posted @ 2023-09-19 11:16  zerozabuu  阅读(496)  评论(0编辑  收藏  举报