Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

fs.watch load file has cache #916

Open
mannymu opened this issue May 19, 2022 · 1 comment
Open

fs.watch load file has cache #916

mannymu opened this issue May 19, 2022 · 1 comment

Comments

@mannymu
Copy link

mannymu commented May 19, 2022

`const fs = require('fs');
const path = require('path');

require('@babel/register')({
cache: false,
});

process.env.ESM_DISABLE_CACHE = true

const requireModule = require('esm')(module, {
cache: false, cjs: { cache: false }, force: true }
);

const getESM = (path)=>{
let esmModule = {};
try {
esmModule = requireModule(path);
} catch (e) {
console.trace('requireModule Error:', e);
}
//本地开发时,fs.watch重新打包时有问题
return esmModule.default || esmModule;
}

const baseDir = path.resolve(__dirname,"./src");

function build(){
let result = getESM(path.resolve(baseDir, './config.js'));
console.log(result);
}

build();
fs.watch(baseDir,{ persistent: true, recursive: true },(, filename)=>{
console.log(
,filename);
build()
});
`
When I change the config.js file, the result is still cached before.

node : v16.13.1
npm: 8.1.2

@mannymu
Copy link
Author

mannymu commented May 20, 2022

image

I have solved it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant