-
Notifications
You must be signed in to change notification settings - Fork 36
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
monacoEditorPlugin is not a function #21
Comments
hello, I’d be grateful if you could provide the error github responsitory |
I also got this problem but solved. Using vite 2.7.2. Here's my snippet: import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
svelte(),
monacoEditorPlugin.default({
languageWorkers: ['json', 'editorWorkerService'],
customWorkers: [
{
label: 'graphql',
entry: 'monaco-graphql/dist/graphql.worker'
}
]
})
],
clearScreen: false
}) |
Should replace In ECMAScript module, export default xxx
// equals
export const default = xxx
// after compile
exports.default = xxx export = xxx
// after compile
exports = xxx Can you add a new export export { monacoEditorPlugin }; |
@SaltyAom Thanks a lot,
|
@china-bin This happens when you set the type field as The .default trick works but would love a proper fix to this. See https://github.com/skalidindi/VitePlayground/tree/monaco for repro |
The
I'm not skilled enough to diagnose the reason i'm getting it, but I did manage to silence the error by casting it to ...
plugins: [
(monacoEditorPlugin as any).default()
],
... |
declaring |
From what I can see, PR #45 provided by @AkaraChen is the best solution for this problem as it brings the plugin to modern standards. @china-bin any chance of getting that PR reviewed and if everything is ok, merged? In the meantime, this is my solution which I believe to be fully TypeScript safe and does not use import monacoEditorPluginModule from 'vite-plugin-monaco-editor'
const isObjectWithDefaultFunction = (module: unknown): module is { default: typeof monacoEditorPluginModule } => (
module != null &&
typeof module === 'object' &&
'default' in module &&
typeof module.default === 'function'
)
const monacoEditorPlugin = isObjectWithDefaultFunction(monacoEditorPluginModule)
? monacoEditorPluginModule.default
: monacoEditorPluginModule
export default defineConfig({
plugins: [
monacoEditorPlugin({})
]
}) |
I'm having the same issue since updating to vite 5. @pedrolamas your solution is the only one that works for me, but it would be great to get that PR merged to have it properly exported. |
(monacoEditorPlugin as unknown as {default: typeof monacoEditorPlugin}).default({
languageWorkers: ['json', 'editorWorkerService'],
customWorkers: [/* ... */],
}), Unfortunately! 😢 |
Having the same issue, was able to resolve it using the "default" hack. Then applying a ts-ignore and specifying that the options are still import monacoEditorPlugin, { type IMonacoEditorOpts } from 'vite-plugin-monaco-editor' // @ts-ignore
monacoEditorPlugin.default({
languageWorkers: ['editorWorkerService', 'json'],
globalAPI: true,
customWorkers: [
{
label: 'json',
entry: 'monaco-editor/esm/vs/language/json/json.worker'
},
],
} as IMonacoEditorOpts) |
Hello everyone I suffered for a very long time with monaco editor on SvelteKit, after which I came across this plugin. I was very happy, I did everything according to the points described in the README, but at startup I received the following error, after which the Vite process ended:
If you do not specify monacoEditorPlugin as a function (with parentheses), then Vite starts, but the following error crashes in the console:
Thank you in advance for your help
The text was updated successfully, but these errors were encountered: