我对Webpack配置和cjs,mjs等之间的差异很陌生。当试图构建Webpack捆绑的组件库时,我在构建时遇到了这个错误(webpack
命令)
BREAKING CHANGE: The request './components' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
字符串
当将index.js
添加到./components/
时,它工作得很好,但我希望我的webpack能够自己解决它。请注意,我使用package.json type:module
来使用import
syntex我的webpack配置:
import path from "path";
/**
* @type {import('webpack').Configuration}
*/
export default {
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.resolve(process.cwd(), "./dist"),
},
resolve: {
extensions: [".js", ".jsx"],
fullySpecified: false,
},
mode: "development",
devtool: "source-map",
module: {
rules: [
{
type: "javascript/auto",
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
},
},
],
},
],
},
};
型
1条答案
按热度按时间kiz8lqtg1#
通过将
resolve: { fullySpecified: false },
添加到rules
部分中的babel规则来解决它