Ecommerce Shopify WordPress Discussion

Vite config started failing on build for shopify app [duplicate]

This question already has answers here: Uncaught ReferenceError: require is not defined [Shopify PHP-React Browser issue] (3 answers) Closed 3 months ago. The frontend build for my shopify app has all of sudden started to error out. I haven't made code changes since so there is something up with packages or some breaking change. Running the app locally still works without issue but as soon as I build to production the embedded fails to render: index-d27b9a09.js:79 Uncaught ReferenceError: require is not defined at index-d27b9a09.js:79:72236 This is due to the require statement being outputted into the index.js bundle but this was not occcuring previously. Below is my vite configuration: import { defineConfig } from "vite"; import { dirname } from "path"; import { fileURLToPath } from "url"; import https from "https"; import react from "@vitejs/plugin-react"; if ( process.env.npm_lifecycle_event === "build" && !process.env.CI && !process.env.SHOPIFY_API_KEY ) { console.warn( "\nBuilding the frontend app without an API key. The frontend build will not run without an API key. Set the SHOPIFY_API_KEY environment variable when running the build command.\n" ); } const proxyOptions = { target: `${process.env.BACKEND_PORT}`, changeOrigin: false, secure: true, ws: false, }; const host = process.env.HOST ? process.env.HOST.replace(/https?:\/\//, "") : "localhost"; let hmrConfig; if (host === "localhost") { hmrConfig = { protocol: "ws", host: "localhost", port: 64999, clientPort: 64999, }; } else { hmrConfig = { protocol: "wss", host: host, port: process.env.FRONTEND_PORT, clientPort: 443, }; } export default defineConfig({ root: dirname(fileURLToPath(import.meta.url)), plugins: [react()], define: { "process.env.SHOPIFY_API_KEY": JSON.stringify(process.env.SHOPIFY_API_KEY), }, resolve: { preserveSymlinks: true, }, server: { host: "localhost", port: process.env.FRONTEND_PORT, hmr: hmrConfig, proxy: { "^/(\\?.*)?$": proxyOptions, "^/api(/|(\\?.*)?$)": proxyOptions, "^/bundle/checkout(\\?.*)?$": proxyOptions, }, }, }); From what I have researched the fix potentially could be to add the commonjs transformations to the vite build to be able to support the require statement versus the import. I am just confused on why this would be necessary now as it was not before and I was importing react without issue. Just want to make sure im going down the right rabbit hole here and would be nice to understand why this is occurring. Updated, below is my package.json { "name": "shopify-frontend-template-react", "version": "1.0.0", "private": true, "license": "UNLICENSED", "scripts": { "build": "vite build", "dev": "vite", "coverage": "vitest run --coverage" }, "type": "module", "engines": { "node": ">= 12.16" }, "stylelint": { "extends": "@shopify/stylelint-polaris" }, "dependencies": { "@formatjs/intl-locale": "^3.3.2", "@formatjs/intl-localematcher": "^0.4.0", "@formatjs/intl-pluralrules": "^5.2.4", "@shopify/app-bridge": "^3.7.7", "@shopify/app-bridge-react": "^3.7.7", "@shopify/i18next-shopify": "^0.2.3", "@shopify/polaris": "^10.49.1", "@shopify/react-form": "^2.5.5", "@shopify/react-hooks": "^3.0.5", "@vitejs/plugin-react": "1.2.0", "dayjs": "^1.11.9", "i18next": "^23.1.0", "i18next-resources-to-backend": "^1.1.4", "react": "^17.0.2", "react-dom": "^17.0.2", "react-i18next": "^13.0.0", "react-query": "^3.34.19", "react-router-dom": "^6.3.0", "vite": "^4.3.9" }, "devDependencies": { "@shopify/stylelint-polaris": "^12.0.0", "history": "^5.3.0", "jsdom": "^19.0.0", "prettier": "^2.6.0", "stylelint": "^15.6.1", "vi-fetch": "^0.6.1" } }
The Shopify internal dev teams have investigated this issue and it appears it was related to our i18nFormat plugin for the i18next library. We've shipped a fix to the above plugin to resolve this, so to fix this issue developers should update @shopify/i18next-shopify to 0.2.9. If anyone is still experiencing this problem after updating please let us know.

December 30, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.