Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant