Unable to infer path to ace from script src
See original GitHub issueUnable 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:
- Created a year ago
- Reactions:4
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@wfmonster @28development Add
import 'ace-builds/webpack-resolver'
and it will solve this errorJust import
import ace from 'ace-builds/src-noconflict/ace';
beforeimport AceEditor from 'react-ace';
No need of
'ace-builds/webpack-resolver'
which does not work with Webpack 5+