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.

Unable to infer path to ace from script src

See original GitHub issue

Unable to infer path to ace from script src

I am using react ace in my Next.js Project, so far the editor seems to work but my chrome dev console returns following error message which I would like to understand and fix:

Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes or with webpack use ace/webpack-resolver 
    at ReactAce (webpack-internal:///./node_modules/.pnpm/react-ace@10.1.0_sfoxds7t5ydpegc3knd667wn6m/node_modules/react-ace/lib/ace.js:38:28)
    at Editor (webpack-internal:///./src/components/Editor/index.tsx:35:22)
    at LoadableImpl (webpack-internal:///./node_modules/.pnpm/next@12.1.6_sfoxds7t5ydpegc3knd667wn6m/node_modules/next/dist/shared/lib/loadable.js:101:38)

Sample code to reproduce your issue

This is how my Editor component looks like:

import { ComponentProps, useState } from 'react';
import AceEditor from 'react-ace';

// import mode-<language> , this imports the style and colors for the selected language.
import 'ace-builds/src-noconflict/mode-javascript';
// there are many themes to import, I liked monokai.
import 'ace-builds/src-noconflict/theme-monokai';
import 'ace-builds/src-noconflict/theme-xcode';
// this is an optional import just improved the interaction.
import 'ace-builds/src-noconflict/ext-language_tools';
import 'ace-builds/src-noconflict/ext-beautify';
import { FieldValues, UseFormReturn, SubmitHandler } from 'react-hook-form';
import { Shimmer } from '../ui/Shimmer';
import useHasMounted from '~/hooks/useHasMounted';

interface Props<T extends FieldValues = any>
	extends Omit<ComponentProps<'form'>, 'onSubmit'> {
	form: UseFormReturn<T>;
	onSubmit?: SubmitHandler<T>;
}

const Editor = ({ form, onSubmit }: Props) => {
	const hasMounted = useHasMounted();
	const [value, setValue] = useState('');
	const [mode, setMode] = useState('javascript');
	const [theme, setTheme] = useState('xcode');

	if (!hasMounted) {
		return <Shimmer />;
	}

	return (
		<AceEditor
			{...form.register('content')}
			style={{
				width: '100%',
			}}
			placeholder="Start Coding"
			mode={mode}
			theme={theme}
			name="basic-code-editor"
			onChange={(v) => setValue(v)}
			fontSize={18}
			showPrintMargin={true}
			showGutter={true}
			highlightActiveLine={true}
			value={value}
			setOptions={{
				enableBasicAutocompletion: true,
				enableLiveAutocompletion: true,
				enableSnippets: true,
				showLineNumbers: true,
				tabSize: 4,
			}}
		/>
	);
};

export default Editor;

I am also importing the component using dynamic in my parent like this:

const Editor = dynamic(() => import('~/components/Editor'), { ssr: false });

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

5reactions
tomercohen1210commented, Jul 6, 2022

@wfmonster @28development Add import 'ace-builds/webpack-resolver' and it will solve this error

0reactions
ea167commented, Nov 16, 2022

Just import import ace from 'ace-builds/src-noconflict/ace'; before import AceEditor from 'react-ace';

No need of 'ace-builds/webpack-resolver' which does not work with Webpack 5+

Read more comments on GitHub >

github_iconTop Results From Across the Web

theme and mode path infer issue with ace.js and Angular
ace.js:1 Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes ...
Read more >
themes and modes doesnt work, looks for them on root #766
... theme and the mode are not found stating: Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enabl....
Read more >
Ace Editor modes and themes don't load when js and css is ...
When using downloaded library and not CDN, Ace Editor modes and themes fail to load when js is aggregated. The cause is because...
Read more >
Developers - js error - Unable to infer path to ace from script src -
ace.js:1 Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes ...
Read more >
ajaxorg/ace - Gitter
Hello everyone, there is a problem,error:"Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of ...
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