Then load http://localhost:3000/ in your browser to access the app.npm install --save leafletnpm install --save leaflet-draw到这里一切正常!在app.js中,我添加以下这一行:In app.js I add this single line:var L = require('leaflet');并得到我粘贴的丑陋错误and get the ugly error I pasted/home/diego/Escritorio/fundacion/node_modules/leaflet/dist/leaflet-src.js:9168}(window, document)); ^ReferenceError: window is not defined at Object.<anonymous> (/home/diego/Escritorio/fundacion/node_modules/leaflet/dist/leaflet-src.js:9168:3) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/home/diego/Escritorio/fundacion/app.js:10:9) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10)npm ERR! weird error 8npm WARN This failure might be due to the use of legacy binary "node"npm WARN For further explanations, please read/usr/share/doc/nodejs/README.Debian推荐答案这是Leaflet本身的问题. Leaflet尝试加载DOM而不检查其是否可用.我认为您可以通过模拟应用程序中的浏览器来加载传单.It's an issue with Leaflet itself. Leaflet tries to load the DOM without checking if it's available or not. I think you can load leaflet by simulating the browser in your app.// Create globals so leaflet can loadGLOBAL.window = {};GLOBAL.document = { documentElement: { style: {} }, getElementsByTagName: function() { return []; }, createElement: function() { return {}; }};GLOBAL.navigator = { userAgent: 'nodejs'};GLOBAL.L = require('leaflet');您也可以通过以下方式来了解一下:叶无头You can also tale a look at this: leaflet-headless 这篇关于Node.js Leaflet错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-02 22:55
查看更多