dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.
https://craco.js.org
Apache License 2.0
7.42k stars 501 forks source link

use-ts-loader recipe not working #422

Open fs86 opened 2 years ago

fs86 commented 2 years ago

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 commented 1 year ago

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

samchon commented 1 year ago

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 commented 7 months ago

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)