Skip to content

ts-loader throwing an error when attempting to build with transpileOnly and happyPackMode set to false #2171

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

Closed
ol-ko opened this issue Aug 12, 2018 · 2 comments

Comments

@ol-ko
Copy link

ol-ko commented Aug 12, 2018

Version

3.0.0

Node and OS info

node 10.8.0, npm 6.2.0, macOS HighSierra 10.13.6

Steps to reproduce

What is expected?

I'm trying to build a TypeScript project using vue-cli with a --target lib setting.

As I need typings along with the bundle files, I've tried to make vue.config.js set transpileOnly and happyPackMode options of ts-loader to false by doing the following:

module.exports = {
    chainWebpack: config => {
        config.module
            .rule('ts')
            .use('ts-loader')
            .loader('ts-loader')
            .tap(opts => {
                opts.transpileOnly = false;
                opts.happyPackMode = false;
                return opts;
            });
    }
};

What is actually happening?

Unfortunately, building with this configuration results in an error thrown by ts-loader:

Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 2)
Cannot read property 'options' of undefined

    at Object.makeServicesHost (/Users/olga/code/homegate-ui/ui/node_modules/ts-loader/dist/servicesHost.js:18:66)
    at successfulTypeScriptInstance (/Users/olga/code/homegate-ui/ui/node_modules/ts-loader/dist/instances.js:164:45)
    at Object.getTypeScriptInstance (/Users/olga/code/homegate-ui/ui/node_modules/ts-loader/dist/instances.js:51:12)
    at Object.loader (/Users/olga/code/homegate-ui/ui/node_modules/ts-loader/dist/index.js:16:41)

 @ ./node_modules/@vue/cli-service/lib/commands/build/entry-lib-no-default.js 2:0-22 2:0-22

Full source code of the project can be found here: https://github.com/ol-ko/vue-cli-ts-loader-error

Creating an issue here, as same versions of ts-loader (4.4.2) and webpack (4.16.5) seem to work fine in isolation from vue-cli.

Thanks!

@zhangyinag
Copy link

@ol-ko I have the same problem, I try to remove "thread-loader", it worked, my vue.config.js as below:

module.exports = {
  configureWebpack: config => {
    config.module.rules.forEach(v => {
      if (v.use) {
        let idx = v.use.findIndex(w => w.loader === 'thread-loader')
        if (idx !== -1) v.use.splice(idx, 1)
      }
    })
  },
  chainWebpack: config => {
    config.module
      .rule('ts')
      .use('ts-loader')
      .loader('ts-loader')
      .tap(options => {
        Object.assign(options || {}, {transpileOnly: false, happyPackMode: false})
        return options
      })
    config.module
      .rule('tsx')
      .use('ts-loader')
      .loader('ts-loader')
      .tap(options => {
        Object.assign(options || {}, {transpileOnly: false, happyPackMode: false})
        return options
      })
  }
}

@ohrinish
Copy link

ohrinish commented Jun 3, 2020

thread-loader really cause this issue, so to disable it:

chainWebpack: config => 
      config.module.rule('ts').uses.delete('thread-loader')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants