Node.js Leaflet错误 [英] Node.js Leaflet error

查看:272
本文介绍了Node.js Leaflet错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助!!我知道我错过了一些非常简单的东西,但是我是新手,我阅读了许多不同的文章和教程,并且无法理解错误之处.

Please help!! I know I'm missing something very simple but I'm new to all this and I read lots of different post and tutorial and can't get whats wrong.

我在Ubuntu 14.04上启动一个新项目 导航到我希望我的应用程序存在的文件夹.

I initiate a new project on Ubuntu 14.04 Navigate to the folder I want my app to be.

这是我要采取的步骤:

sudo apt-get install nodejs-legacy
sudo npm install express-generator -g  (framework)

express -e --ejs (Establece el lenguaje ejs como base) 
https://www.npmjs.com/package/ejs
npm install

要运行应用程序DEBUG=myapp:* npm start

然后在浏览器中加载 http://localhost:3000/来访问该应用.

Then load http://localhost:3000/ in your browser to access the app.

npm install --save leaflet
npm 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 8
npm 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 load
GLOBAL.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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆