Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected character '' error #174

Open
croxydev opened this issue Sep 16, 2023 · 4 comments
Open

Unexpected character '' error #174

croxydev opened this issue Sep 16, 2023 · 4 comments

Comments

@croxydev
Copy link

image

my packages:

"electron": "^21.3.3",
"electron-builder": "^23.6.0",
"next": "^12.3.4",
"nextron": "^8.7.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"@uiw/react-monacoeditor": "^3.5.9",

how can i fix this?

@jaywcjlove
Copy link
Member

@croxywastaken

To import a TTF file in Next.js, you need to configure the appropriate loader in the next.config.js file of your project.

Here is an example next.config.js file that demonstrates how to configure the loader for importing TTF files:

module.exports = {
  webpack: (config, { isServer }) => {
    // Add a loader for TTF files
    config.module.rules.push({
      test: /\.(woff|woff2|eot|ttf|otf)$/,
      use: {
        loader: 'file-loader',
        options: {
          name: '[name].[ext]',
          publicPath: '/_next/static/fonts',
          outputPath: 'static/fonts',
          esModule: false,
        },
      },
    });

    // Configure behavior when importing TTF files on the server-side
    if (isServer) {
      const originalEntry = config.entry;
      config.entry = async () => {
        const entries = await originalEntry();
        if (entries['main.js'] && !entries['main.js'].includes('./utils/fix-ttf-import.js')) {
          entries['main.js'].unshift('./utils/fix-ttf-import.js');
        }
        return entries;
      };
    }

    return config;
  },
};

This configuration file does the following:

  1. Adds a loader for TTF files using file-loader to handle the import of font files.
  2. Configures the behavior when importing TTF files on the server-side to ensure that the font files load correctly during server-side rendering.

Additionally, you need to create a file named fix-ttf-import.js in the utils directory of your project with the following content:

if (typeof window !== 'undefined') {
  require('monaco-editor/min/vs/base/browser/ui/codicons/codicon/codicon.ttf');
}

This file is responsible for importing the TTF file on the browser-side.

Please note that the above configuration is suitable for Next.js version 10 and above. If you are using an older version, refer to the respective documentation or community resources for the appropriate configuration method.

@croxydev
Copy link
Author

Now it gives me this error :(
image

My code:

import React, { useEffect, useRef, useState } from "react";
import MonacoEditor from '@uiw/react-monacoeditor';

function App() {
	const [code, setCode] = useState('')
	
  return ( 
    <>
      <div className="bg-white marker:shadow-lg flex flex-col text-sm select-none">
            <main className="bg-dark-700">
              <div className="main-content">
                <div className="bg-gray-1">
				<MonacoEditor
					language="html"
					value="<h1>I ♥ react-monacoeditor</h1>"
					options={{
						theme: 'vs-dark',
					}}
				/>
                </div>
              </div>
            </main>
      </div>
    </>
  );
}

export default App;

@croxydev
Copy link
Author

Btw, i'm using this module on electron app. (next.js + electron)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants