[英]Gulp webpack can't resolve imported class
我正在與babel-loader和webpack一起使用gulp。 我的gulp拋出錯誤,說gulp找不到我要導入的分隔文件
這是錯誤(由於缺少類而導致的其他錯誤)
internal/streams/legacy.js:59
throw er; // Unhandled stream error in pipe.
^
Error: ./src/client.js
Module not found: Error: Can't resolve 'game/modules/Game' in '/home/k3nzie/projects/jsGame/src'
resolve 'game/modules/Game' in '/home/k3nzie/projects/jsGame/src'
Parsed request is a module
using description file: /home/k3nzie/projects/jsGame/package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/k3nzie/projects/jsGame/package.json (relative path: ./src)
resolve as module
/home/k3nzie/projects/jsGame/src/node_modules doesn't exist or is not a directory
/home/k3nzie/projects/node_modules doesn't exist or is not a directory
/home/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
looking for modules in /home/k3nzie/projects/jsGame/node_modules
using description file: /home/k3nzie/projects/jsGame/package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/k3nzie/projects/jsGame/package.json (relative path: ./node_modules)
using description file: /home/k3nzie/projects/jsGame/package.json (relative path: ./node_modules/game/modules/Game)
no extension
Field 'browser' doesn't contain a valid alias configuration
/home/k3nzie/projects/jsGame/node_modules/game/modules/Game doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/home/k3nzie/projects/jsGame/node_modules/game/modules/Game.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/home/k3nzie/projects/jsGame/node_modules/game/modules/Game.json doesn't exist
as directory
/home/k3nzie/projects/jsGame/node_modules/game/modules/Game doesn't exist
looking for modules in /home/k3nzie/node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
/home/k3nzie/node_modules/game/modules/Game doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/home/k3nzie/node_modules/game/modules/Game.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/home/k3nzie/node_modules/game/modules/Game.json doesn't exist
as directory
/home/k3nzie/node_modules/game/modules/Game doesn't exist
[/home/k3nzie/projects/jsGame/src/node_modules]
[/home/k3nzie/projects/node_modules]
[/home/node_modules]
[/node_modules]
[/home/k3nzie/node_modules/package.json]
[/home/k3nzie/projects/jsGame/node_modules/game/modules/Game]
[/home/k3nzie/projects/jsGame/node_modules/game/modules/Game.js]
[/home/k3nzie/node_modules/game/modules/Game/package.json]
[/home/k3nzie/projects/jsGame/node_modules/game/modules/Game.json]
[/home/k3nzie/node_modules/game/modules/Game]
[/home/k3nzie/projects/jsGame/node_modules/game/modules/Game]
[/home/k3nzie/node_modules/game/modules/Game.js]
[/home/k3nzie/node_modules/game/modules/Game.json]
[/home/k3nzie/node_modules/game/modules/Game]
@ ./src/client.js 1:0-41main.js from UglifyJs
Unexpected token: name (socket) [main.js:74,4]
雖然這是文件結構
- src
- game
- modules/
- Game.js (class)
- client.js (main file)
我已經將Game
類導入到client.js
如下所示:
import Game from 'game/modules/Game';
它應該找到課程,但沒有,我在做什么錯?
編輯:更正后的錯誤
throw er; // Unhandled stream error in pipe.
^
Error: main.js from UglifyJs
Unexpected token: name (game) [main.js:82,4]
如果我注釋掉另一個變量
internal/streams/legacy.js:59
throw er; // Unhandled stream error in pipe.
^
Error: main.js from UglifyJs
Unexpected token: name (socket) [main.js:75,4]
這些是正確的類Game導入后client.js中的變量:
let socket = io();
let game = new Game();
導入路徑錯誤,請嘗試import Game from './game/modules/Game'
;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.