我正在使用带有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]
在正确的游戏类导入后,这些是client.js中的变量:
let socket = io();
let game = new Game();
答案 0 :(得分:0)
导入路径错误,请尝试使用import Game from './game/modules/Game'
;