question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InvalidCharacterError: String contains an invalid character

See original GitHub issue

Hi,

Running a project with Expo, I am getting an InvalidCharacterError: String contains an invalid character error on the web rendering. Android works fine and I haven’t tested iOS.

I have the following dependencies in my package.json:

{
  ...
  "dependencies": {
    "expo": "~37.0.3",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
    "react-native-svg": "11.0.1",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "~8.1.0",
    "react-native-svg-transformer": "^0.14.3"
  }
}

Here is my App.js, the Bower SVG was taken from react-native-svg-example:

import React from 'react';
import { StyleSheet, View } from 'react-native';
import Bower from './assets/bower.svg';

export default function App() {
  return (
    <View style={styles.container}>
      <Bower width={256} height={256} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Does anyone have an idea of what’s going on?

Thanks

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jtojnarcommented, Nov 7, 2020

This transformer only seems to be used for Android and iOS.

For Web, I found that I needed the following webpack.config.js:

const createExpoWebpackConfigAsync = require("@expo/webpack-config");
const { createAllLoaders } = require("@expo/webpack-config/loaders");

// Expo CLI will await this method so you can optionally return a promise.
module.exports = async (env, argv) => {
  const config = await createExpoWebpackConfigAsync(env, argv);

  config.module.rules = [
    // Enable svgr in web build.
    {
      oneOf: [
        {
          test: /\.svg$/,
          exclude: /node_modules/,
          use: [
            {
              loader: "@svgr/webpack",
            },
          ],
        },
      ].concat(createAllLoaders(env)),
    },
  ];

  // Finally return the new config for the CLI to use.
  return config;
};

For completeness, this is what I added to package.json:

{
  "dependencies": {
    "react-native-svg": "^12.1.0"
  },
  "devDependencies": {
    "@expo/webpack-config": "^0.12.40",
    "@svgr/webpack": "^5.4.0",
    "react-native-svg-transformer": "^0.14.3",
 }
}

and for Android into metro.config.js:

const { getDefaultConfig } = require("metro-config");

module.exports = (async () => {
  const {
    resolver: { sourceExts, assetExts },
  } = await getDefaultConfig();

  return {
    transformer: {
      babelTransformerPath: require.resolve("react-native-svg-transformer"),
    },
    resolver: {
      assetExts: assetExts.filter((ext) => ext !== "svg"),
      sourceExts: [...sourceExts, "svg"],
    },
  };
})();

I also have added the following to app.json but have no idea if it is necessary:

{
  "expo": {
   "packagerOpts": {
      "config": "metro.config.js",
      "sourceExts": [
        "expo.ts",
        "expo.tsx",
        "expo.js",
        "expo.jsx",
        "ts",
        "tsx",
        "js",
        "jsx",
        "json",
        "wasm",
        "svg"
      ]
    }
  }
}
0reactions
pascalhuszarcommented, Nov 7, 2020

@Beetix did you found a solution or some kind of workaround? Have the same problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

'String contains an invalid character' when using document ...
The string you pass to document.createElement is the type of the element, e.g. tr . If you really want to assemble your HTML...
Read more >
1627511 - "String contains an invalid character" even though ...
I receive the error "InvalidCharacterError: String contains an invalid character". This is confusing because all characters in the string are valid base 64....
Read more >
Uncaught DOMException: String contains an invalid character ...
Hi, all. I've been looking through my code, trying to find where the stray character is, but I just cannot find it.
Read more >
InvalidCharacterError: String contains an invalid character
InvalidCharacterError : String contains an invalid character. ... email subject contains: č; response contains: ď. Other characters with ...
Read more >
The message contains invalid characters. - Apple Developer
I'm trying to post a legitimate question but I keep getting this error that says "The message contains invalid characters." I tried "rephrasing"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found