Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

TypeError: Cannot read property '_tsInstances' of undefined #541

Closed
iHaiduk opened this issue Feb 26, 2018 · 10 comments
Closed

TypeError: Cannot read property '_tsInstances' of undefined #541

iHaiduk opened this issue Feb 26, 2018 · 10 comments

Comments

@iHaiduk
Copy link

iHaiduk commented Feb 26, 2018

I have error with new version webpack.

~/node_modules/awesome-typescript-loader/src/instance.ts:73
if (!compiler) {
^
    TypeError: Cannot read property '_tsInstances' of undefined
    at resolveInstance (~/node_modules/awesome-typescript-loader/src/instance.ts:73:20)
    at ~/node_modules/awesome-typescript-loader/src/instance.ts:366:26
    at AsyncSeriesHook.eval [as callAsync] (eval at create (~/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:16:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (~/node_modules/webpack/node_modules/tapable/lib/Hook.js:35:21)
    at Watching._go (~/node_modules/webpack/lib/Watching.js:40:32)
    at Watching._invalidate (~/node_modules/webpack/lib/Watching.js:164:9)
    at watcher.compiler.watchFileSystem.watch (~/node_modules/webpack/lib/Watching.js:135:10)
    at Watchpack.watcher.once (~/node_modules/webpack/lib/node/NodeWatchFileSystem.js:43:4)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Watchpack.emit (events.js:214:7)
    at Watchpack._onTimeout (~/node_modules/watchpack/lib/watchpack.js:142:7)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)

package.json

{
  "scripts": {
    "build:dev": "./node_modules/.bin/webpack --colors --config ./webpack.config.js --mode development",
    "build:prod": "./node_modules/.bin/webpack --colors --config ./webpack.config.js",
    "run:dev": "./node_modules/.bin/nodemon ./dist/index.js",
    "lint-typescript": "./node_modules/.bin/tslint ./src/**/* -c tslint.json",
    "lint-typescript-fix": "./node_modules/.bin/tslint ./src/**/* -c tslint.json --fix"
  },
  "devDependencies": {
    "@types/axios": "0.14.0",
    "@types/node": "9.4.6",
    "@types/pino": "4.7.1",
    "awesome-typescript-loader": "3.5.0",
    "babel-loader": "7.1.3",
    "babel-plugin-closure-elimination": "1.3.0",
    "babel-plugin-loop-optimizer": "1.4.1",
    "babel-preset-env": "1.6.1",
    "babel-preset-stage-0": "6.24.1",
    "nodemon": "1.15.1",
    "source-map-loader": "0.2.3",
    "ts-loader": "4.0.0",
    "tslint": "5.9.1",
    "typescript": "2.7.2",
    "webpack": "4.0.1",
    "webpack-bundle-analyzer": "2.11.0",
    "webpack-cli": "2.0.9",
    "webpack-error-notification": "0.1.7",
    "webpack-node-externals": "1.6.0"
  },
  "dependencies": {
    "@types/mongoose": "5.0.3",
    "axios": "0.18.0",
    "cheerio": "1.0.0-rc.2",
    "fast-html-parser": "1.0.1",
    "html-parser": "0.11.0",
    "mongoose": "5.0.7",
    "node-cmd": "3.0.0",
    "pino": "4.13.0",
    "query-hash": "2.0.1"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es2017",
    "outDir": "dist",
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "inlineSources": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "types": ["node"],
    "typeRoots": ["./node_modules/@types"],
    "baseUrl": ".",
    "paths": {
      "_config":            [ "./src/config.ts" ],
      "_interfaces":        [ "./src/interfaces.ts" ],
      "_controller/*":      [ "./src/controllers/*" ],
      "_model/*":           [ "./src/models/*" ],
      "_utils/*":           [ "./src/utils/*" ]
    }
  },
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true,
    "useCache": true,
    "cacheDirectory": ".gulp/ts",
    "useTranspileModule": true,
    "silent": true,
    "useBabel": true,
    "babelOptions": {
      "presets": ["stage-0", ["env", { "targets": { "node": "current" } }]],
      "plugins": ["closure-elimination", "loop-optimizer"]
    }
  },
  "exclude": [
    ".gulp",
    "node_modules",
    "server",
    "dist"
  ],

  "include": [
    "./src/**/*"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

webpack.config.js

const nodeExternals = require('webpack-node-externals');
const {resolve} = require('path');
const webpack = require('webpack');
const WebpackErrorNotificationPlugin = require('webpack-error-notification');
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');


module.exports = {

    target: "node",

    entry: {
        index: resolve(__dirname, 'src', 'index.ts'),
    },

    // Currently we need to add '.ts' to the resolve.extensions array.
    resolve: {
        modules: ['node_modules'],
        extensions: ['.tsx', '.ts', '.js'],
        descriptionFiles: ['package.json'],
        alias: {
            "_config": resolve(__dirname, 'src', 'config.ts'),
            "_interfaces": resolve(__dirname, 'src', 'interfaces.ts'),
            "_controller": resolve(__dirname, 'src', 'controllers'),
            "_model": resolve(__dirname, 'src', 'models'),
            "_utils": resolve(__dirname, 'src', 'utils'),
        },
    },

    output: {
        path: resolve(__dirname, 'dist'),
        filename: '[name].js',
        chunkFilename: '[name]-[id].js',
        libraryTarget: 'commonjs2'
    },

    // Source maps support ('inline-source-map' also works)
    devtool: 'inline-source-map',
    externals: [nodeExternals()],

    stats: {
        colors: true,
        modules: true,
        reasons: true,
        errorDetails: true
    },

    node: {
        console: false,
        global: true,
        process: true,
        Buffer: true,
        __filename: true,
        __dirname: true,
        setImmediate: true
    },

    // Add the loader for .ts files.
    module: {
        rules: [
            {
                enforce: 'pre',
                test: /\.ts(x?)$/,
                use: "source-map-loader",
                exclude: /node_modules/,
            },
            {
                test: /\.ts(x?)$/,
                use: [
                    {loader: 'awesome-typescript-loader'}
                ],
                include: [
                    resolve(__dirname, 'src')
                ],
                exclude: /node_modules/,
            }
        ]
    },
    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.NamedModulesPlugin(),
        new WebpackErrorNotificationPlugin(),
        // new CheckerPlugin(),

        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify('development')
            }
        }),

        new BundleAnalyzerPlugin({
            openAnalyzer: false,
        }),
    ],

    watch: true,
};
@s-panferov
Copy link
Owner

webpack4?

@darklightcode
Copy link

darklightcode commented Feb 27, 2018

I get if (!compiler._tsInstances) , yet it's on the same line as iHaiduk's log.
When i start the server everything goes ok, no errors, but when i change even a string and recompiling starts, the app crashes with the error below, i'm using:

Webpack 4.0.1 + webpack-dev-middleware
npm v5.6.0
node v8.9.3

~\node_modules/awesome-typescript-loader/src/instance.ts:73
     if (!compiler._tsInstances) {
                   ^
    TypeError: Cannot read property '_tsInstances' of undefined
        at resolveInstance (~/node_modules/awesome-typescript-loader/src/instance.ts:73:20)
        at ~/node_modules/awesome-typescript-loader/src/instance.ts:366:26
    at _err1 (eval at create (~/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:21:1)
    at invalid (~/node_modules/webpack-dev-middleware/lib/context.js:76:7)
    at context.compiler.plugin (~/node_modules/webpack-dev-middleware/lib/context.js:116:5)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (~/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:16:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (~/node_modules/webpack/node_modules/tapable/lib/Hook.js:35:21)
    at Watching._go (~/node_modules/webpack/lib/Watching.js:40:32)
    at Watching._invalidate (~/node_modules/webpack/lib/Watching.js:164:9)
    at watcher.compiler.watchFileSystem.watch (~/node_modules/webpack/lib/Watching.js:135:10)
    at Watchpack.watcher.once (~/node_modules/webpack/lib/node/NodeWatchFileSystem.js:43:4)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Watchpack.emit (events.js:214:7)
    at Watchpack._onTimeout (~/node_modules/watchpack/lib/watchpack.js:142:7)
    at ontimeout (timers.js:475:11)

I'm using ts-loader for now as a compiler, it works with atl checker :

const { CheckerPlugin } = require('awesome-typescript-loader');

module.exports = function () {
    module: {
       rules: [
                {
                    test: /\.ts?$/,
                    loaders: ['ts-loader'],
                    exclude: /(node_modules|bower_components)/
                }
       ]
    },
    plugins: [
      new CheckerPlugin()
    ]
}

@xingyun909
Copy link

you can use ts-loader

@amitdahan
Copy link

Happens to me as well, only on incremental builds. Webpack 4.0.1, at-loader 4.0.0-0.
seems like compiler is undefined in the resolveInstance function, whatever that means :)

@s-panferov
Copy link
Owner

Duplicate of #534

@s-panferov s-panferov marked this as a duplicate of #534 Feb 27, 2018
@kmvan
Copy link
Contributor

kmvan commented Mar 19, 2018

same problem on Webpack4.1.1

@quantuminformation
Copy link

Having this issue, causing caching of old postcss files

@alveshelio
Copy link

I'm having the same issue, whenever I save a file and it tries to recompile I get this error. I'm using Webpack 4 and awesome-typescript-loader 4.0.1.
Any idea what could be the problem?

@kuldeepkeshwar
Copy link

@alveshelio I'm also facing same issue, have you got it working ?

niik added a commit to desktop/desktop that referenced this issue May 9, 2018
I was getting [a TypeError](s-panferov/awesome-typescript-loader#541) when running webpack dev server (worked fine for initial compile but crashed on reload). Upgrading to latest a-t-l seems to have solved it
yurydelendik added a commit to wasdk/WebAssemblyStudio that referenced this issue May 15, 2018
Amaimersion added a commit to Amaimersion/2ch-helper that referenced this issue Jul 8, 2018
I was getting [an Error](s-panferov/awesome-typescript-loader#541) when running webpack in the watch mode. Upgrade to latest version seems to have solved it
@zhujun24
Copy link

zhujun24 commented Dec 5, 2018

awesome-typescript-loader@5.0.0-1 work well

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

10 participants