多线程中引入的js文件中函数无法调用
发布于 5 年前 作者 chao62 14174 次浏览 来自 问答

index.js


const utils = require(’./utils’)

console.log(‘hello worker’) //这句确认输出

worker.onMessage(function(res) {

    console.log(‘bg’, res)

    utils.test();

    console.log(‘aaaaa’, utils)

    worker.postMessage({

    msg: '0'

    })

})


utils.js


console.log(‘ttttt’) //这句确认输出

function test() {

    console.debug(‘test’)

    return 1 + 1

}




调用的时候提示:

Uncaught TypeError: utils.test is not a function


1 回复

没有 export 呀

回到顶部