简体   繁体   English

Webpack 未创建 bundle.js 或错误消息

[英]Webpack not creating bundle.js or error messages

I've tried installing webpack and babel-loader into my vue project.我已经尝试将 webpack 和 babel-loader 安装到我的 vue 项目中。 When I run 'npm run dev' in my terminal, I don't get any bundled files outputted to my dist folder and I get the following message:当我在终端中运行“npm run dev”时,没有任何捆绑文件输出到我的 dist 文件夹,并且收到以下消息:

> vueproject@0.1.0 dev

> webpack --watch --progress --mode=development

If I run npm run serve , I get this:如果我运行npm run serve ,我会得到:

 Module parse failed: Unexpected token (2:5) You may need an appropriate loader to handle this file type. | import requests | from django.shortcuts import render | from rest_framework import viewsets | from django.db import connection # This is for the my_custom_sql method. @./node_modules/cache-loader/dist/cjs.js??ref--12-0../node_modules/babel-loader/lib.?/node_modules/cache-loader/dist/cjs?js.?ref--0-0?./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist.?ref--0-1::/src/App.vue.vue&type=script&lang=js 5?0-52 139.18-31 @./src/App.vue.vue&type=script&lang=js @?/src/App:vue @./src/main.js @ multi (webpack)-dev-server/client.http://172.25.10.80:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

If I run npm run build , I get this error:如果我运行npm run build ,我会收到以下错误:

 TypeError: Class extends value undefined is not a constructor or null at Object.<anonymous> (C:\Users\user\Documents\GitHubRepositories\Django_Repository\DB_Vue_Project\vueproject\node_modules\mini-css-extract-plugin\dist\CssDependency.js:12:46) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Module.require (internal/modules/cjs/loader.js:952:19) at require (internal/modules/cjs/helpers.js:88:18) at Object.<anonymous> (C:\Users\user\Documents\GitHubRepositories\Django_Repository\DB_Vue_Project\vueproject\node_modules\mini-css-extract-plugin\dist\index.js:12:45) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) npm ERR. code ELIFECYCLE npm ERR. errno 1 npm ERR: vueproject@0.1.0 build. `vue-cli-service build` npm ERR. Exit status 1 npm ERR. npm ERR: Failed at the vueproject@0:1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2021-04-28T03_13_56_408Z-debug.log

Here's my file structure in my project:这是我项目中的文件结构:

 -vueproject -dist -src -deletethis.js package.json package-lock.json webpack.config.js babel.config.js

package.json: package.json:

 { "name": "vueproject", "version": "0.1.0", "private": true, "scripts": { "test": "webpack", "dev": "webpack --watch --progress --mode=development", "prod": "webpack --mode=production", "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" }, "dependencies": { "@tailwindcss/line-clamp": "^0.2.0", "autoprefixer": "^9.8.6", "axios": "^0.21.1", "bcryptjs": "^2.4.3", "core-js": "^3.6.5", "mysql": "^2.18.1", "postcss": "^7.0.35", "postcss-loader": "^5.2.0", "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.1.0", "vue": "^3.0.0", "vue-router": "^3.5.1" }, "devDependencies": { "@babel/core": "^7.13.16", "@vue/cli-plugin-babel": "~4.5.0", "@vue/cli-plugin-eslint": "~4.5.0", "@vue/cli-service": "~4.5.0", "@vue/compiler-sfc": "^3.0.0", "autoprefixer": "^10.2.5", "babel-eslint": "^10.1.0", "babel-loader": "^8.2.2", "eslint": "^6.7.2", "eslint-plugin-vue": "^7.0.0", "path": "^0.12.7", "postcss": "^8.2.9", "postcss-cli": "^8.3.1", "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.1.0", "webpack": "^4.0.0", "webpack-cli": "^4.6.0" }, "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ "plugin:vue/vue3-essential", "eslint:recommended" ], "parserOptions": { "parser": "babel-eslint" }, "rules": {} }, "browserslist": [ "> 1%", "last 2 versions", "not dead" ] }

webpack.config.js: webpack.config.js:

 // webpack.config.js const path = require('path'); // Define the path module, which is used for handling and transforming file paths. module.exports = { // Makes the object on the right side of the equals sign available to the outside world (webpack). context: __dirname, // Allows 'entry' to take the root of the path that you have defined. entry: 'src/deletethis.js', // Tells webpack which file(s)/modules it needs to bundle. output: { // Defines where webpack outputs the bundled file. path: path.resolve(__dirname, 'dist'), publicPath: '/dist/', filename: 'testdeletethis.js', }, module: { rules: [ // Ensures that whenever webpack finds a *.js file, it uses babel-loader to convert it to ES5. { test: /\.js$/, exclude: /node_modules/, use: 'babel-loader', } ] } };

I've looked around the internet for a few hours today but wasn't able to find anything quite like what I'm running into.我今天在互联网上浏览了几个小时,但找不到与我遇到的情况完全一样的东西。 I find it odd that those two lines are all that I'm getting when I run 'npm run dev'.我觉得奇怪的是,当我运行“npm run dev”时,这两行就是我得到的全部。 Any help with this issue would be appreciated.对此问题的任何帮助将不胜感激。 Thanks, all!谢谢大家!

Your dev script only runs the Webpack dev server, so nothing would be written into dist .您的dev脚本仅运行 Webpack 开发服务器,因此不会将任何内容写入dist Also, bundling only occurs (and the dist folder created and filled) when you run the build script ( npm run build ).此外,仅当您运行build脚本( npm run build )时才会发生捆绑(以及创建和填充的dist文件夹)。

But your project appears to be a Vue CLI scaffolded project (based on the @vue/cli-service dependencies), which transitively depends on Webpack, so you don't need to add a dependency on webpack or webpack-cli .但是您的项目似乎是一个 Vue CLI 脚手架项目(基于@vue/cli-service依赖项),它传递地依赖于 Webpack,因此您不需要添加对webpackwebpack-cli的依赖项。

Your Webpack config doesn't seem to do anything that isn't already done by default in Vue CLI scaffolded projects.您的 Webpack 配置似乎没有做任何在 Vue CLI 脚手架项目中默认没有做的事情。 I recommend just sticking with the serve and build scripts.我建议坚持使用servebuild脚本。 If you need to change the Webpack config, use vue.config.js 's configureWebpack or chainWebpack .如果您需要更改 Webpack 配置,请使用vue.config.jsconfigureWebpackchainWebpack See Working with Webpack for reference.请参阅使用 Webpack以获取参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM