Skip to content
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

Module build failed: TypeError: Cannot read property 'afterCompile' of undefined #729

Closed
James34Shaw100 opened this issue Feb 26, 2018 · 14 comments

Comments

@James34Shaw100
Copy link

I've just installed this module to use with Laravel's Mix that uses Webpack under the covers. Followed guide for setup here: https://sebastiandedeyne.com/posts/2017/typescript-with-laravel-mix

I'm getting a similar error to:
#728

Module build failed: TypeError: Cannot read property 'afterCompile' of undefined
at successfulTypeScriptInstance (/.../node_modules/ts-loader/dist/instances.js:147:27)
at Object.getTypeScriptInstance (/.../node_modules/ts-loader/dist/instances.js:48:12)
at Object.loader (/.../node_modules/ts-loader/dist/index.js:16:41)

@johnnyreilly
Copy link
Member

It sounds like one of the things in the mix isn't webpack 4... I'll leave this open for now but I suspect this isn't a ts-loader issue.

@James34Shaw100
Copy link
Author

Tested switching from manual configuration to simpler built-in ts support in Mix support. webpack.mix.js now looks like this:

let mix = require('laravel-mix');
mix.autoload({
    'jquery': ['$', 'window.jQuery', 'jQuery'],
    'vue': ['Vue','window.Vue'] 
});
mix.webpackConfig({
    resolve: {
        alias: {
            '@': path.resolve('resources/assets/sass'),
        }
    }
});
mix.js('resources/assets/js/bootstrap.js', 'public/js').version();
mix.js('resources/assets/js/app.js', 'public/js').version();
mix.ts('resources/assets/js/admin.ts', 'public/js').version();

mix.sass('resources/assets/sass/app.scss', 'public/css').version()

mix.copyDirectory('resources/assets/images', 'public/images');
mix.copy('node_modules/trumbowyg/dist/ui/icons.svg', 'public/css');

mix.then(function () {
    require('child_process').exec('php artisan laroute:generate', null, (error, stdout, stderr) => {
        if (error) {
            throw error;
        }
        console.log(stdout);
    });
});

I also stripped down admin.ts to just:

import Vue from 'vue'
const app = new Vue({
    el: '#app'
});

to make sure there wasn't any actual errors for it to run in to. But still nothing.

@griffonn
Copy link

griffonn commented Feb 26, 2018

Also happens while running webpack right away:

webpack --config webpack.config.js
ERROR in ./index.ts Module build failed: TypeError: Cannot read property 'afterCompile' of undefined

Config:

const path = require('path');

module.exports = {
    entry: './index.ts',
    devtool: 'inline-source-map',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/
            }
        ]
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js']
    },
    output: {
        filename: 'output.js',
        path: path.resolve(__dirname, 'dist')
    }
};

@johnnyreilly
Copy link
Member

Whenever you see Cannot read property 'afterCompile' of undefined it probably means ts-loader is dealing with webpack 3 not webpack 4.

@johnnyreilly
Copy link
Member

Maybe install ts-loader 3.5.0 if you're not using webpack 4?

1 similar comment
@johnnyreilly
Copy link
Member

Maybe install ts-loader 3.5.0 if you're not using webpack 4?

@James34Shaw100
Copy link
Author

Can confirm it was a versioning issue. Laravel Mix is presently still on older version of webpack at time of writing. TypeScript compiler was able to run once I swapped out for the 3.5.0 version of ts-loader.

@johnnyreilly
Copy link
Member

Thanks for confirming!

@an5rag
Copy link

an5rag commented Mar 9, 2018

Saved me from endlessly trying different options - thanks @johnnyreilly!

@liu2080019
Copy link

@johnnyreilly thank u````

@johnnyreilly
Copy link
Member

My pleasure!

@boogie4eva
Copy link

Thanks @johnnyreilly This worked for me .

@sakalys
Copy link

sakalys commented Apr 6, 2018

For those coming from angular 5+ world. This means that you must install ts-loader v3.x if ng -v says that webpack version is 3.x.

@danurasenan
Copy link

Hello,

This is not part of this question. but any one how to fix this.

ReferenceError: self is not defined
    at Object.eeMe (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:199163:4)
    at __webpack_require__ (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:20:30)
    at Module.YpNe (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:176155:66)
    at __webpack_require__ (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:20:30)
    at Module.UZG+ (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:163034:78)
    at __webpack_require__ (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:20:30)
    at Module.c9hY (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:188309:100)
    at __webpack_require__ (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:20:30)
    at Module.IqRD (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:97334:82)
    at __webpack_require__ (D:\Projects\Angular\backend angular CSL\dist\multikart-backend\server\main.js:20:30)

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

8 participants