0
我正在使用Angular Universal,Express和Webpack。我開始使用這個混帳回購協議的應用程序:錯誤:找不到模塊「。」
https://github.com/FrozenPandaz/ng-universal-demo
我似乎無法在我的main.server.ts使用socket.io。我可以進口,但試圖安裝時,它起來,我得到一個錯誤:
...
import * as express from 'express';
import * as socket from 'socket.io';
enableProdMode();
const app = express();
const server = require('http').Server(app);
const io = socket(server);
// . ^^ causes error
app.engine('html', ngExpressEngine({
bootstrap: ServerAppModule
}));
app.set('view engine', 'html');
app.set('views', 'src');
app.use('/', express.static('dist', {index: false}));
server.listen(1337);
app.get('test', (req, res) => {
res.render('../dist/index', {
req: req,
res: res
});
});
io.on('connection', (socket) => {
socket.on('register', (data) => {
socket.join(data);
user = data;
});
});
該錯誤是因爲socket(server)
調用的發生,因爲如果我評論了這一點的錯誤不會發生:
/Users/michaelwilson/Code/app/dist/server.js:101828
return /*require.resolve*/(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
^
Error: Cannot find module "."
at webpackMissingModule (/Users/michaelwilson/Code/app/dist/server.js:101828:76)
at resolvePath (/Users/michaelwilson/Code/app/dist/server.js:101828:154)
at Server.serveClient (/Users/michaelwilson/Code/app/dist/server.js:101831:25)
at new Server (/Users/michaelwilson/Code/app/dist/server.js:101770:8)
at Server (/Users/michaelwilson/Code/app/dist/server.js:101762:41)
at Object.<anonymous> (/Users/michaelwilson/Code/app/dist/server.js:113993:10)
at __webpack_require__ (/Users/michaelwilson/Code/app/dist/server.js:26:30)
at /Users/michaelwilson/Code/app/dist/server.js:94:18
at Object.<anonymous> (/Users/michaelwilson/Code/app/dist/server.js:97:10)
at Module._compile (module.js:570:32)
[nodemon] app crashed - waiting for file changes before starting...
我不確定還有什麼可以嘗試的,這是Webpack + Socket.io的問題嗎?我找不到任何人有同樣的問題...
編輯:我已經找到了這個代碼在socket.io庫發生,其行試圖做一個動態的決心:
return /*require.resolve*/(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
檢查:https://stackoverflow.com/questions/34823655/webpack-missing-module-module-not-found 此外,請確保您已經安裝了您正確引用的那些軟件包(它們是否在package.json和node_modules文件夾中?) –
@EdmundoRodrigues該錯誤與我所引用的任何模塊無關,如果是這種情況,它將在socket.io本身內。但事實是「。」無法找到,似乎不是這種情況... –