Closed frankvdb7 closed 6 years ago
When using typescript-ioc in a webworker, the following error occurs: index.js?40f3:11 Uncaught TypeError: fs_1.existsSync is not a function
index.js?40f3:11 Uncaught TypeError: fs_1.existsSync is not a function
The isBrowser() check is correct, because a webworker doesn't has a renderer or window object. But it isn't a Node.js environment either.
I manually fixed it by using the following:
'use strict'; var isBrowser = new Function('try {return this===window;}catch(e){return false;}'); var useES6 = false; if (!isBrowser() && !(self instanceof WorkerGlobalScope)) { useES6 = process.env.ES6 === 'true'; if (!useES6) { var fs_1 = require('fs'); var path_1 = require('path'); var searchConfigFile = function () { var configFile = path_1.join(__dirname, 'ioc.config'); while (!fs_1.existsSync(configFile)) { var fileOnParent = path_1.normalize(path_1.join(path_1.dirname(configFile), '..', 'ioc.config')); if (configFile === fileOnParent) { return null; } configFile = fileOnParent; } return configFile; }; var CONFIG_FILE = searchConfigFile(); if (CONFIG_FILE && fs_1.existsSync(CONFIG_FILE)) { var config = JSON.parse(fs_1.readFileSync(CONFIG_FILE)); if (config.es6) { useES6 = true; } } } } module.exports = require(useES6 ? './es6' : './es5');
I can create a pull request for this, but it's just a trivial change.
When using typescript-ioc in a webworker, the following error occurs:
index.js?40f3:11 Uncaught TypeError: fs_1.existsSync is not a function
The isBrowser() check is correct, because a webworker doesn't has a renderer or window object. But it isn't a Node.js environment either.
I manually fixed it by using the following:
I can create a pull request for this, but it's just a trivial change.