简体   繁体   English

Laravel TypeError:无法读取未定义的属性“js”

[英]Laravel TypeError: Cannot read property 'js' of undefined

I know there are other questions about "Cannot read property 'X' of undefined" error in Laravel, but each of them have different fix depended to X .我知道 Laravel 中还有关于“无法读取未定义的属性‘X’”错误的其他问题,但每个问题都有不同的修复取决于 X 。

Error i receive when i run npm run watch or npm run dev is:我在运行npm run watchnpm run dev时收到的错误是:

 @ dev C:\Users\ME\Documents\CBLOG
> node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/s
etup/webpack.config.js

C:\Users\ME\Documents\CBLOG\webpack.mix.js:15
mix.js('resources/assets/js/app.js', 'public/js')
    ^

TypeError: Cannot read property 'js' of undefined
    at Object.<anonymous> (C:\Users\ME\Documents\CBLOG\webpack.mix.js:15:5)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\ME\Documents\CBLOG\node_modules\laravel-mix\setup\webpack.config.js:12:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_module
s/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I tried many Install/uninstall fixes about npm , webpack and even deleting node_modules folder and reinstalling by npm install command, but no luck.我尝试了许多关于 npm 、 webpack 的安装/卸载修复,甚至删除node_modules文件夹并通过npm install命令重新npm install ,但没有运气。

Package.json包.json

 "private": true,
  "scripts": {
    "dev": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "axios": "^0.19.0",
    "bootstrap-sass": "^3.4.1",
    "cross-env": "^5.2.0",
    "jquery": "^3.4.1",
    "laravel-mix": "^4.0.16",
    "lodash": "^4.16.2",
    "vue": "^2.6.10"
  },
  "dependencies": {
    "laravel-echo": "^1.5.4",
    "pusher-js": "^4.4.0",
    "webpack": "^2.1.0-beta.22",
    "webpack-cli": "^3.3.5"
  }

webpack.mix.js webpack.mix.js

const { mix } = require('laravel-mix');

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

Simply remove the braces surrounding the mix on your first line:只需删除第一行中mix周围的括号:

const mix = require('laravel-mix');

It does not work with the braces because laravel-mix does not use a named export.它不适用于大括号,因为laravel-mix不使用命名导出。

You can have a look at this answer for more information about imports and exports: When should I use curly braces for ES6 import?您可以查看此答案以获取有关导入和导出的更多信息: 何时应使用花括号进行 ES6 导入?

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

相关问题 TypeError:无法读取未定义节点js的属性“ then” - TypeError: Cannot read property 'then' of undefined node js events.js:141 TypeError:无法读取undefined的属性&#39;send&#39; - events.js:141 TypeError: Cannot read property 'send' of undefined TypeError:无法读取tsc.js中未定义的属性“ length” - TypeError: Cannot read property 'length' of undefined in tsc.js TypeError:无法读取未定义的node.js的属性“ length” - TypeError: Cannot read property 'length' of undefined node.js Node JS PostgreSQL TypeError:无法读取未定义的属性&#39;then&#39; - Node JS PostgreSQL TypeError: Cannot read property 'then' of undefined Node.js TypeError:无法读取未定义的属性“路径” - Node.js TypeError: Cannot read property 'path' of undefined Node.js TypeError无法读取未定义的属性objectId - Node.js TypeError Cannot read property objectId of undefined Node.js和jdbc:TypeError:无法读取undefined的属性&#39;url&#39; - Node.js and jdbc : TypeError: Cannot read property 'url' of undefined js:TypeError:无法读取未定义的属性“替换”使用 - js: TypeError: Cannot read property 'replace' of undefined using 类型错误:无法读取 Node.js 和 puppeteer 中未定义的属性“匹配” - TypeError: Cannot read property 'match' of undefined in Node.js and puppeteer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM