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

use-ts-loader recipe not working #422

Open
fs86 opened this issue May 23, 2022 · 3 comments
Open

use-ts-loader recipe not working #422

fs86 opened this issue May 23, 2022 · 3 comments

Comments

@fs86
Copy link

fs86 commented May 23, 2022

The use-ts-loader recipe (https://github.com/gsoft-inc/craco/blob/master/recipes/use-ts-loader/craco.config.js) does not seem to work correctly. The url-loader is not found and the process terminates at line 37. I have prepared an example repository where the error is reproducible: https://github.com/fs86/use-ts-loader

url-loader-not-found

EDIT:
Is this possibly related to the missing CRA5 support?

@dilanx
Copy link
Owner

dilanx commented Oct 2, 2022

@fs86 sorry for the long delay. It looks like your demo repo isn't available anymore. Can you recreate it?

@samchon
Copy link

samchon commented Oct 6, 2022

I'm using a revised code not occuring any bug, but transformation never be happened.

When I trace the program parameter, there're not any source file in the program.

For reference, version of @craco/craco is 7.0.0-alpha.8.

const craco = require("@craco/craco");
const webpack = require("webpack");
const transform = require("typescript-json/lib/transform").default;

const throwError = (message) =>
    craco.throwUnexpectedConfigError({
        packageName: "craco",
        githubRepo: "gsoft-inc/craco",
        message,
        githubIssueQuery: "webpack",
    });

module.exports = {
    webpack: {
        plugins: [
            new webpack.DefinePlugin({
                process: {
                    env: {}
                }
            }),
            new webpack.ProvidePlugin({
                Buffer: ["buffer", "Buffer"],
            }),
        ],
        configure: (config) => {
            // ADD TS-LOADER
            const { isAdded: tsLoaderIsAdded } = craco.addBeforeLoader(
                config,
                craco.loaderByName("babel-loader"),
                {
                    test: /\.(ts|tsx)$/,
                    exclude: /node_modules/,
                    loader: "ts-loader",
                    options: {
                        // TRANSFORMED, BUT NOT BUNDLED
                        getCustomTransformers: (program) => {
                            console.log(program.getSourceFiles()); // NO FILE
                            return {
                                before: [transform(program)],
                            }
                        },
                    },
                },
            );
            if (!tsLoaderIsAdded) throwError("failed to add ts-loader");

            // REMOVE BABEL
            const { hasRemovedAny, removedCount } = craco.removeLoaders(
                config,
                craco.loaderByName("babel-loader"),
            );
            if (!hasRemovedAny) throwError("no babel-loader to remove");
            if (removedCount !== 2)
                throwError("had expected to remove 2 babel loader instances");

            return config;
        },
    },
};

@SeedyROM
Copy link

SeedyROM commented Jan 22, 2024

Anyone get this same issue? (Edit: gonna take that as a no, looks like it's eject time! Don't know why everyone is so afraid of ejecting... sounds a little uninformed)

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

No branches or pull requests

4 participants