File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed
Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 2424 "pino" : " ^10.1.0" ,
2525 "react" : " 18.3.1" ,
2626 "react-dom" : " 18.3.1" ,
27+ "react-input-mask" : " ^2.0.4" ,
2728 "react-router-dom" : " 6.30.1" ,
2829 "sass" : " ^1.96.0"
2930 },
3637 "@types/govuk-frontend" : " ^5.11.0" ,
3738 "@types/react" : " 18.3.1" ,
3839 "@types/react-dom" : " 18.3.1" ,
40+ "@types/react-input-mask" : " ^3.0.6" ,
3941 "@vitejs/plugin-react-swc" : " ^4.2.2" ,
4042 "axios-mock-adapter" : " ^2.1.0" ,
4143 "sass" : " ^1.96.0" ,
Original file line number Diff line number Diff line change 1+ import "./shims/require-shim"
12import React from "react"
23import ReactDOM from "react-dom/client"
34import { BrowserRouter } from "react-router-dom"
Original file line number Diff line number Diff line change 1+ // Shim for packages that incorrectly use CommonJS require() in ES modules
2+ // This is specifically for nhsuk-react-components-extensions which incorrectly
3+ // uses require('react-input-mask') in its ES module build
4+
5+ import ReactInputMask from "react-input-mask"
6+
7+ // Add require to the global scope for the browser environment only
8+ if ( typeof window !== "undefined" ) {
9+ // Create a require function specifically for react-input-mask
10+ function browserRequire ( id : string ) : unknown {
11+ if ( id === "react-input-mask" ) {
12+ return ReactInputMask
13+ }
14+ throw new Error ( `require() is not supported in browser ES modules. Module requested: ${ id } ` )
15+ }
16+
17+ // Assign to globalThis if require doesn't already exist
18+ if ( ! ( globalThis as Record < string , unknown > ) . require ) {
19+ ; ( globalThis as Record < string , unknown > ) . require = browserRequire
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ export default defineConfig(({mode}) => {
4040 }
4141 }
4242 } ,
43- define : envWithProcessPrefix
43+ define : {
44+ ...envWithProcessPrefix ,
45+ "global" : "globalThis"
46+ } ,
47+ optimizeDeps : {
48+ include : [ "react-input-mask" ] ,
49+ exclude : [ ]
50+ }
4451 }
4552} )
You can’t perform that action at this time.
0 commit comments