Error with 'import' statement without .js extension using npm module with Laravel Mix

夙愿已清 提交于 2020-12-12 12:14:26

问题


I'm using CKEditor 5 in a Laravel project, getting it from a CDN, so initially I have not needed to run npm. But now I need an alignment plugin, so I used Laravel Mix to run npm install, and then copy the plugin to public folder. Like this:

mix.copyDirectory('node_modules/@ckeditor', 'public/@ckeditor');

In my code, I tried to import it:

import Alignment from '/@ckeditor/ckeditor5-alignment/src/alignment.js';

So it threw this error in console

Uncaught TypeError: Failed to resolve module specifier "@ckeditor/ckeditor5-core/src/plugin". Relative references must start with either "/", "./", or "../".

I solved it by auto replacing all @ckeditor/ckeditor5-core/src references in the plugin with /@ckeditor/ckeditor5-core/src

But now, it's throwing these import errors, and it's because of the lack of .js extension inside the plugin codes when importing

alignment.js:10 GET http://localhost:8000/@ckeditor/ckeditor5-core/src/plugin net::ERR_ABORTED 404 (Not Found)

alignment.js:12 GET http://localhost:8000/@ckeditor/ckeditor5-alignment/src/alignmentediting net::ERR_ABORTED 404 (Not Found)

alignment.js:13 GET http://localhost:8000/@ckeditor/ckeditor5-alignment/src/alignmentui net::ERR_ABORTED 404 (Not Found)

My question is if there is some tool to add the extension in the end of these import statements, or if there is an easier way to use this npm module without running Node.js as I'm a total noob with npm.

来源:https://stackoverflow.com/questions/59046216/error-with-import-statement-without-js-extension-using-npm-module-with-larave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!