sindresorhus / import-fresh

Import a module while bypassing the cache
MIT License
284 stars 25 forks source link

ES2015/Babel conflict when using import-fresh inside functions #7

Closed mor10 closed 5 years ago

mor10 commented 6 years ago

When using Gulp 4 and Babel, placing import-fresh inside a function causes a TypeError. The odd thing is this doesn't happen if the import-fresh call happens at root:

// Works as expected:
var works = importFresh(path.resolve('./src/stuff'))

function something() {
    // Errors out:
    var worksNot = importFresh(path.resolve('./src/otherStuff'))
}

The error:

TypeError: Cannot read property 'getFileName' of undefined
    at module.exports (/(...)/node_modules/caller-path/index.js:4:40)
    at module.exports.moduleId (/(...)/node_modules/import-fresh/index.js:11:44)
    at imported (/(...)/gulpfile.babel.js:14:14)
    at /(...)/gulpfile.babel.js:28:2
    at taskWrapper (/(...)/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at asyncRunner (/(...)/node_modules/async-done/index.js:55:18)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

When the same script runs without Babel, it works as expected. So there's something weird happening with Babel / ES2015 conversion.

sindresorhus commented 5 years ago

Should be fixed in v3.0.0.