Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Can not apply transform with ts-loader. #43

Open
maksnester opened this issue Jun 21, 2019 · 3 comments
Open

Can not apply transform with ts-loader. #43

maksnester opened this issue Jun 21, 2019 · 3 comments

Comments

@maksnester
Copy link

maksnester commented Jun 21, 2019

Hello there

I'm trying to use your transformer to get simple output instead of nested proxy-objects, but I struggle with that error now:

Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: Cannot read property 'getTypeChecker' of undefined
    at visitNode (C:\Users\Foo\Desktop\vue-project\node_modules\ts-optchain\dist\transform\transform.js:22:31)
    at visitNodeAndChildren (C:\Users\Foo\Desktop\vue-project\node_modules\ts-optchain\dist\transform\transform
.js:19:30)
    at C:\Users\Foo\Desktop\vue-project\node_modules\ts-optchain\dist\transform\transform.js:15:65
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1390:86
    at reduceLeft (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1102:30)
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1390:42
    at transformRoot (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81154:82)
    at Object.map (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:429:29)
    at Object.transformNodes (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81141:
30)
    at emitJsFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81497:32)
    at emitSourceFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81465
:13)
    at forEachEmittedFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81373:30)
    at Object.emitFiles (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81454:9)
    at emitWorker (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:86927:33)
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:86887:66
    at runWithCancellationToken (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:869
79:24)

I tried to integrate your transform fn into my webpack config which I used to build vue based project, so I just wanted to utilize that getCustomTransformers option so after the edits config looks like that:

const optChainTransform = require('ts-optchain/transform').default

module.exports = {
    /*...*/
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader',
        exclude: /node_modules/,
        options: {
          transpileOnly: true,
          getCustomTransformers: (program) => ({
              after: [optChainTransform(program)]
          }),
          appendTsSuffixTo: [/\.vue$/]
        }
      }
      /*...*/
    ],
    plugins: [new VueLoaderPlugin(), new ForkTsCheckerWebpackPlugin()],

tsconfig:

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": ".",
    "downlevelIteration": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "inlineSources": true,
    "jsx": "preserve",
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ],
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "./compiled/",
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": false,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types",
      "src/shims"
    ],
    "types": [
      "webpack-env",
      "jest"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue"
  ]
}

I use common typescript compiler, because I couldn't make it done with ttsc - output bundle still have not-replaced oc() calls so it's still just recursive-proxy objects which I want to avoid. I thought maybe the problem in transpileOnly but I can't refuse from it, project builds too long without it - so I started to search a way how to utilize this transform thing with my current config and I believed the code I provided above should work, but it doesn't. So I just wanted to ask maybe you have some ideas why, because I have no idea at the moment.

Thanks in advance.

upd: Tried it both with typescript 3.2.4 and 3.5.2

@maksnester
Copy link
Author

Changing options to

getCustomTransformers: () => ({
              after: [optChainTransform]
          }),

gives another error:

Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: Cannot read property 'kind' of undefined
    at Object.isSourceFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:13697:21
)
    at emitShebangIfNeeded (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:83984:20
)
    at Object.writeFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81838:13)
    at printSourceFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:8160
2:25)
    at emitJsFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81518:13)
    at emitSourceFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81465
:13)
    at forEachEmittedFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81373:30)
    at Object.emitFiles (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81454:9)
    at emitWorker (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:86927:33)
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:86887:66
    at runWithCancellationToken (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:869
79:24)
    at Object.emit (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:86887:20)
    at Object.transpileModule (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:10517
2:17)
    at getTranspilationEmit (C:\Users\Foo\Desktop\vue-project\node_modules\ts-loader\dist\index.js:231:74)
    at successLoader (C:\Users\Foo\Desktop\vue-project\node_modules\ts-loader\dist\index.js:33:11)
    at Object.loader (C:\Users\Foo\Desktop\vue-project\node_modules\ts-loader\dist\index.js:21:12)

@maksnester
Copy link
Author

maksnester commented Jun 24, 2019

Changing import to as described here:

getCustomTransformers: resolve('build/webpack.ts-transformers.js')

Gives another error

\typescript.js:63475:36)
    at visitSourceFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:66199:53)
    at saveStateAndInvoke (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:65832:27
)
    at transformSourceFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:65815:2
7)
    at transformSourceFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js
:65795:20)
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1390:86
    at reduceLeft (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1102:30)
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1390:42
    at transformRoot (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81154:82)
    at Object.map (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:429:29)
    at Object.transformNodes (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81141
:30)
    at emitJsFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81497:32
)
    at emitSourceFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:8146
5:13)
    at forEachEmittedFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81373:30
)

@maksnester
Copy link
Author

Changing after to before gives yet another error:

Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: Cannot read property 'length' of undefined
    at Object.firstOrUndefined (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:998
:22)
    at Object.startsWithUseStrict (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:
62523:33)
    at Object.visitLexicalEnvironment (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript
.js:63475:36)
    at visitSourceFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:66199:53)
    at saveStateAndInvoke (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:65832:27
)
    at transformSourceFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:65815:2
7)
    at transformSourceFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js
:65795:20)
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1390:86
    at reduceLeft (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1102:30)
    at C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:1390:42
    at transformRoot (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81154:82)
    at Object.map (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:429:29)
    at Object.transformNodes (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81141
:30)
    at emitJsFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81497:32
)
    at emitSourceFileOrBundle (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:8146
5:13)
    at forEachEmittedFile (C:\Users\Foo\Desktop\vue-project\node_modules\typescript\lib\typescript.js:81373:30
)

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

No branches or pull requests

1 participant