TypeError: m._compiler is not a function

来源:2-8 开发时的服务端渲染

505380967

2018-10-15

const Module = module.constructor

const mfs = new MemoryFs
const serverCompiler = webpack(serverConfig)
serverCompiler.outputFileSystem = mfs
let serverBundle
serverCompiler.watch({},(err,stats) => {
    if(err) throw err
    stats = stats.toJson()
    stats.errors.forEach(err => console.error(err))
    stats.warnings.forEach(warn => console.warn(warn))

    const bundlePath = path.join(
        serverConfig.output.path,
        serverConfig.output.filename
    )

    const bundle = mfs.readFileSync(bundlePath,'utf-8')
    const m = new Module()
    m._compiler(bundle,'server-entry.js')
    serverBundle = m.default
})

跟着视频一步步来的,webpack是4.启动dev:server时报错,m._compiler is not a function

写回答

1回答

Jokcy

2018-10-16

应该是m._compile吧

0
1
505380967
改了之后const bundle = mfs.readFileSync(bundlePath,'utf-8')又报错了。 这是打印出来的bundlePath:C:\code\projects\react-cnode\dist\server-entry.js 报错信息 Unhandled rejection Error: no such file or directory
2018-10-16
共1条回复

React全栈+服务器渲染(ssr)打造社区Webapp

【毕设面试】只会写业务代码?out了,带你学会搭建属于自己的工程!

768 学习 · 414 问题

查看课程