vscode自动import导致报错

发布时间 2023-09-01 17:43:25作者: 看风景就

vscode自动添加了这么一句

import { Template } from "webpack";

导致出现奇葩错误

Can't resolve 'fs' in '/xxx/Desktop/ncpub/node_modules/.pnpm/move-concurrently@1.0.1/node_modules/move-concurrently

Can't resolve 'fs' in '/xxx/Desktop/ncpub/node_modules/.pnpm/path-exists@3.0.0/node_modules/path-exists'

Can't resolve 'fs' in '/xxx/Desktop/ncpub/node_modules/.pnpm/y18n@4.0.3/node_modules/y18n'

Can't resolve 'module' in '/xxx/Desktop/ncpub/node_modules/.pnpm/webpack@4.46.0_webpack-cli@3.1.1/node_modules/webpack/lib'

ERROR in ./node_modules/.pnpm/fsevents@2.3.3/node_modules/fsevents/fsevents.node 1:0
Module parse failed: Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

错误很诡异,看起来像是缺少包,或node版本问题,删了重装,node也重装,于事无补

好在错误暴漏了原始错误文件

./src/xxx/public/xxx.js

只是代码不是自己加的,也没有git管理,所以不知道错误在此

在此文件逐句排查,可发现错误