Skip to content

Can you give an example of using this with "craco"? #27

@PjotrB

Description

@PjotrB

Your Readme shows how to make toDates work using a modified webpack.config.js.
That would require that I run "eject" on my React project, which is not recommended by just about everyone everywhere, and I'd rather not do it...

As an alternative I am using craco for overriding the configuration of the project.

I tried adding the code from your webpack.config.js to my craco.config.js in a few ways, but it had no effect at all.
I always get this error, both with and without the added config code:

ERROR in ./src/pages/Page.tsx 31:4-11

export 'toDates' (imported as 'toDates') was not found in 'ts-transformer-dates' (possible exports: __esModule, applyToDates, toDatesByArray)"

Below is what my craco.config.js attempts look like. Both attempts do nothing, the above error appears with or without it.

If you could provide code for craco.config.js that makes this work, I would be very grateful!

Attempt # 1:

const datesTransformer = require('ts-transformer-dates/lib/transformer').default;

module.exports = {
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader', // or 'awesome-typescript-loader'
        options: {
          // make sure not to set `transpileOnly: true` here, otherwise it will not work
          getCustomTransformers: program => ({
            before: [datesTransformer(program)]
          })
        }
      }
    ]
  }
}

Attempt # 2, this uses a webpack property that I saw being used somewhere, but that also has no effect at all:

const datesTransformer = require('ts-transformer-dates/lib/transformer').default;

module.exports = {
  webpack: {   // <--- extra property level
    module: {
      rules: [
        {
          test: /\.ts$/,
          loader: 'ts-loader', // or 'awesome-typescript-loader'
          options: {
            // make sure not to set `transpileOnly: true` here, otherwise it will not work
            getCustomTransformers: program => ({
              before: [datesTransformer(program)]
            })
          }
        }
      ]
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions