所以我一直遇到这个NPM错误,我无法弄清楚为什么无法解决VUE。我正在使用Laravel 5.6。这是Laravel的新安装,带有一些简单的Web Pack配置。我已经将webpackConfig中的路径解析为VUE,并且我相信它在webpack.mix.js的提取步骤中失败了
Vue已安装在node_modules / vue中
使用npm run dev和npm run prod生成错误
Package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.10",
"axios": "^0.18",
"babel-jest": "^22.1.0",
"bootstrap": "^4.1.3",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
"pace": "github:HubSpot/pace#v1.0.2",
"perfect-scrollbar": "^1.4.0",
"popper.js": "^1.14.4",
"simple-line-icons": "^2.4.1",
"sweetalert2": "^7.0.7",
"vue": "^2.5.17"
},
"dependencies": {
"imagemin": "^6.0.0"
}
}
webpack.mix.js
let mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.setPublicPath('public');
/*
|--------------------------------------------------------------------------
| Webpack Config
|--------------------------------------------------------------------------
*/
mix.webpackConfig({
resolve: {
modules: [
path.resolve(__dirname, 'node_modules/bootstrap/dist'),
path.resolve(__dirname, 'node_modules/jquery/dist'),
path.resolve(__dirname, 'node_modules/vue'),
path.resolve(__dirname, 'node_modules/axios/dist'),
path.resolve(__dirname, 'node_modules/lodash'),
path.resolve(__dirname, 'node_modules/sweetalert2/dist'),
path.resolve(__dirname, 'node_modules/popper.js/dist')
]
}
});
/*
|--------------------------------------------------------------------------
| Vendor Extraction
|--------------------------------------------------------------------------
*/
mix.extract([
'vue',
'jquery',
'axios',
'sweetalert2',
'lodash',
'js/bootstrap',
'popper.js'
]);
/*
|--------------------------------------------------------------------------
| Autoload Dependancies
|--------------------------------------------------------------------------
*/
mix.autoload({
jquery: ['$', 'window.jQuery', 'jQuery']
});
/*
|--------------------------------------------------------------------------
| Mix App Resources
|--------------------------------------------------------------------------
| app.js | Application Javascript file
| app.scss | Applciation SCSS file
*/
mix
.js(['resources/js/app.js'], 'public/js')
.sass('resources/sass/app.scss', 'public/css');
/*
|--------------------------------------------------------------------------
| Mix In Production
|--------------------------------------------------------------------------
*/
if (mix.inProduction() || process.env.npm_lifecycle_event !== 'hot') {
mix.version();
}
NPM错误
ERROR in multi vue jquery axios sweetalert2 lodash js/bootstrap popper.js
Module not found: Error: Can't resolve 'vue' in '/Path/To/Project/Project-Folder'
@ multi vue jquery axios sweetalert2 lodash js/bootstrap popper.js
app.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('example-component', require('./components/ExampleComponent.vue'));
const app = new Vue({
el: '#app'
});
答案 0 :(得分:0)
在webpack.mix文件中,有以下行:
path.resolve(__dirname, 'node_modules/vue'),
只需确保这是正确的,也许您就需要定位dist文件夹或类似的文件
path.resolve(__dirname, 'node_modules/vue/dist'),