Reworking, Fusion, Prompt, and NX, Tackling Import Problems with @lingui/macro - Unavailable Named Export 'createMacro'

Shoutout to itxch over on GitHub for helping me with the integration of Vite, Remix, and NX.

Currently facing an error that reads:

Error when evaluating SSR module /@fs/Users/joseasilis/Documents/programming/alertdown/nx/nx-remix-vite/libs/ui/src/templates/AuthForm/index.tsx: failed to import "@lingui/macro"
|- file:///Users/joseasilis/Documents/programming/alertdown/nx/nx-remix-vite/node_modules/@lingui/macro/dist/index.mjs:1
import { createMacro } from 'babel-plugin-macros';
         ^^^^^^^^^^^
SyntaxError: Named export 'createMacro' not found. The requested module 'babel-plugin-macros' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'babel-plugin-macros';
const { createMacro } = pkg;

I've attempted manually going into the index.js file within node_modules to destructure it to commonjs format:

const { createMacro } from 'babel-plugin-macros';

However, this method did not resolve the issue.

Included below is my vite.config.ts file:

/// <reference types='vitest' />
import { defineConfig } from 'vite';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { vitePlugin as remix } from '@remix-run/dev';
import { expressDevServer } from 'remix-express-dev-server';
import { denyImports } from 'vite-env-only';
import { lingui } from '@lingui/vite-plugin';
import react from '@vitejs/plugin-react';
export default defineConfig({
  root: __dirname,
  cacheDir: '../../node_modules/.vite/apps/alertdown-vite',
  plugins: [
    expressDevServer(),
    denyImports({}),
    remix(),
    lingui({
      // This is needed for lingui to pickup the config
      cwd: __dirname,
    }),
    nxViteTsPaths(),
  ],

  test: {
    setupFiles: ['test-setup.ts'],
    watch: false,
    globals: true,
    environment: 'jsdom',
    include: ['./tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
    reporters: ['default'],
    coverage: {
      reportsDirectory: '../../coverage/apps/alertdown',
      provider: 'v8',
    },
  },
});

My main package.json details are as follows:

{
  "name": "@alertdown/source",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "dev": "nx dev @alertdown/app",
    "gen": "nx g @nx/js:lib",
    "reset": "nx reset"
  },
  "private": true,
  ...
  ...
}

Any suggestions or solutions to tackle this problem?

Answer №1

Despite initial assumptions, the unconventional solution involved integrating the react's plugin macro into Remix, even though it was deemed unnecessary.

 react({
      babel: {
        plugins: ['macros'],
      },
    }),
/// <reference types='vitest' />
import { defineConfig } from 'vite';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { vitePlugin as remix } from '@remix-run/dev';
import { expressDevServer } from 'remix-express-dev-server';
import { denyImports } from 'vite-env-only';
import { lingui } from '@lingui/vite-plugin';
import react from '@vitejs/plugin-react';
export default defineConfig({
  root: __dirname,
  cacheDir: '../../node_modules/.vite/apps/alertdown-vite',
  plugins: [
    expressDevServer(),
    denyImports({}),
    remix(),
    react({
      babel: {
        plugins: ['macros'],
      },
    }),
    lingui({
      cwd: __dirname,
    }),
    nxViteTsPaths(),
  ],

  test: {
    setupFiles: ['test-setup.ts'],
    watch: false,
    globals: true,
    environment: 'jsdom',
    include: ['./tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
    reporters: ['default'],
    coverage: {
      reportsDirectory: '../../coverage/apps/alertdown',
      provider: 'v8',
    },
  },
});

It is crucial to remember to include cwd: __dirname, for the lingui plugin in order for it to function correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to configure TypeScript for recognizing import paths that include RequireJS plugins such as "plugin!./path/to/foo"?

Let's say we have the following scenario: import template from 'hb!./foo.hb' Is there a way to inform TypeScript about this import statement (or simply ignore it, knowing that RequireJS will take care of it)? ...

Enhancing TypeScript with Generic Functions

Due to limitations in TS syntax, I am unable to use the following: anObject['aKey'] = 'aValue'; To work around this issue, I have created the interfaces below and made all objects inherit from them: interface KeyIndexable { [key: str ...

Executing cypress tests with tags in nrwl nx workspace: A simple guide

Currently, I am working within a nrwl nx workspace where I have set up a cypress BDD cucumber project. My goal is to run cypress tests based on tags using nrwl. In the past, I would typically use the "cypress-tags" command to achieve this. For example: &q ...

The emotions CSS properties do not seem to be applied correctly when utilizing Vite

[email protected] @preact/[email protected] @styled-components/[email protected] [email protected] My preact config { plugins: [ preact({ exclude: /\.stories\.(t|j)sx?$/, babel: { plugins: ...

How does using ngFor and ngModel in Angular cause a change in one select to affect others?

I am looking to implement a feature where users can create multiple select dropdowns, choose options for each one, and then aggregate these selections into an array that will be sent to a parent component. My current approach involves using an *ngFor loop ...

Having trouble sending props

After successfully writing Jest tests for a React site I created 6 months ago, I decided to work on a new project based off the same codebase. However, when I attempted to write similar tests for basic component rendering, they failed unexpectedly. The er ...

Modifying the value upon saving in Adonis JS model

Using Adonis js I am facing an issue when trying to convert an ISO string to Datetime while saving data (the opposite of serializing DateTime fields to ISO string). I cannot find a way to do this in the model, like I would with a mutator in Laravel. Whene ...

Angular 6 is showcasing dates in a quirky manner

In my Angular app, users can enter comments. The comments are displayed automatically with the date they were added. However, there is an odd behavior that I've noticed: When a user enters a comment, the time displayed is incorrect. (Check the ...

Vue/Vite - Exceeded heap capacity, Allocation unsuccessful - Ran out of memory on JavaScript heap (unplugin-vue-components)

I keep encountering a memory problem while working with Vite: I'm getting an error message saying "Reached heap limit Allocation failed - JavaScript heap out of memory" Here is the output: <--- Last few GCs ---> [23466:0x5e196b0] 37408 ms ...

Tips for denoting unnecessary non-null assertions in Typescript

Incorporated this wrapper (source) into the project I'm currently working on: export function expectToBeDefined<T>( arg: T, ): asserts arg is Exclude<T, undefined> { expect(arg).toBeDefined(); } The objective is to eliminate the usage ...

Error encountered: "The requested resource does not have the 'Access-Control-Allow-Origin' header in Angular 6 and Nodejs."

I have encountered an issue with my Angular 6 app and Node.js. When I submit the form, I am receiving the following error: Failed to load http://localhost:3000/contact/send: Response to preflight request doesn't pass access control check: No 'Ac ...

How can we properly retrieve data in order to update the user interface using the useEffect hook and useState in React

I'm diving into the world of Next.js 13 for the first time, attempting to retrieve a cart object from the API and display it on the UI. Utilizing useState to hold the cart object and useEffect to fetch it. However, upon calling setCart(), the UI fail ...

Error in Typescript: The property 'children' is not included in the type but is necessary in the 'CommonProps' type definition

Encountering this error for the first time, so please bear with me. While working on a project, I opened a file to make a change. However, instead of actually making any changes, I simply formatted the file using Prettier. Immediately after formatting, t ...

Prevent selection of future dates and display them in a muted grey color in the p-calendar component

I am attempting to prevent users from selecting future dates and visually distinguish them by setting a grey color background. However, I am having trouble disabling the future dates while the grey color background is functioning correctly. Any ideas on ho ...

Unit testing the TypeScript function with Karma, which takes NgForm as a parameter

As I work on writing unit tests for a specific method, I encounter the following code: public addCred:boolean=true; public credName:any; public addMachineCredential(credentialForm: NgForm) { this.addCred = true; this.credName = credentialForm.val ...

What is the best way to set up the parser and plugins using ESLint's updated flat configuration?

How can ESLint be configured using the new "flat config" system (specifically with the eslint.config.js file) to work seamlessly with both @typescript-eslint/eslint-plugin and /parser? I have been struggling to make ESLint's new configuration system ...

Tips for obtaining response headers

Currently, I am utilizing Angular version 15.0 and retrieving a list of items from the backend (ASP.NET Core 5) with an additional item attached to the header. The GET method in the client-side service is as follows: /** GET Paged commodities from the s ...

The element mat-divider in Angular is unrecognized

While testing a popup component in Angular, I encountered an error message that says: 'mat-divider' is not a known element: 1. If 'mat-divider' is an Angular component, then verify that it is part of this module. 2. If ' ...

Wrapper for Material UI - leverage TypeScript types for a specific property

Apologies if this question has been addressed previously as I was unable to locate an answer. Currently, the app I am developing utilizes a wrapper for certain material-ui components. For example, I have a MyCompanyButton component which acts as a wrapper ...

Struggling to get bcrypt.ts to install on Visual Studio Code for password hashing purposes

As part of my current project, I am working on creating a hash function following the guidelines provided by npmjs's bcrypt documentation: var bcrypt = require('bcrypt.ts'); // Synchronous - 10 rounds equal 10 hashes/sec const saltRounds = ...