I am developing a React Native app using Expo, NativeWind, and Metro. I’m encountering a syntax error related to a CSS import when I try to start my project with npx expo start -c. Here are the details:
Web Bundling failed 9ms C:...appnode_modulesexpo-routerentry.js (1 module)
error: SyntaxError: C:...appglobal.css: The only valid numeric escape in strict mode is ''. (1:17)
> 1 | import 'C:......appnode_modules.cachenativewindglobal.css'
| ^
metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const { withNativeWind } = require('nativewind/metro');
const config = getDefaultConfig(__dirname);
module.exports = withNativeWind(config, { input: './global.css' });
metro.transformer.js
const upstreamTransformer = require("@expo/metro-config/babel-transformer");
const svgTransformer = require("react-native-svg-transformer");
module.exports.transform = async ({ src, filename, options }) => {
// Use react-native-svg-transformer for SVG files
if (filename.endsWith(".svg")) {
return svgTransformer.transform({ src, filename, options });
}
// Pass the source through the upstream Expo transformer for other files
return upstreamTransformer.transform({ src, filename, options });
};
package.json
{
"dependencies": {
"@expo/cli": "^0.18.10",
"expo": "^51.0.2",
"expo-router": "~3.5.11",
"nativewind": "4.0.1",
"react": "18.2.0",
"react-native": "0.74.1"
},
...
}
Additional Information:
The file node_modules.cachenativewindglobal.css.web.css was created successfully.
I tried deleting node_modules folder and the package-lock.json file, and then reinstalling the packages but not not working.
toyofumi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.