问题描述
我仍在尝试在我的内部使用角度2代码镜像模块角度2应用程序.
I am still attempting to get the angular 2 code mirror module working within my angular 2 app.
我遇到了一些导入问题,这些问题已经详细说明,我似乎已经过去了,但是现在我遇到了一个新问题.
I've had some import issues that I've detailed here, that I seem to have gotten past, but now I've run into a new issue.
我最近的堆栈跟踪是这个
My most recent stack trace is this
Error: (SystemJS) require is not a function
@http://localhost:8050/node_modules/ng2-codemirror/lib/codemirror.module.js:8:14
ZoneDelegate.prototype.invoke@http://localhost:8050/node_modules/zone.js/dist/zone.js:232:17
Zone.prototype.run@http://localhost:8050/node_modules/zone.js/dist/zone.js:114:24
scheduleResolveOrReject/<@http://localhost:8050/node_modules/zone.js/dist/zone.js:502:52
ZoneDelegate.prototype.invokeTask@http://localhost:8050/node_modules/zone.js/dist/zone.js:265:21
Zone.prototype.runTask@http://localhost:8050/node_modules/zone.js/dist/zone.js:154:28
drainMicroTaskQueue@http://localhost:8050/node_modules/zone.js/dist/zone.js:401:25
ZoneTask/this.invoke@http://localhost:8050/node_modules/zone.js/dist/zone.js:339:25
Evaluating http://localhost:8050/node_modules/ng2-codemirror/lib/codemirror.module.js
Error loading http://localhost:8050/app/main.js
所以,我没有要求...
So, I don't have require available to me...
这是我的node_modules结构
This is my node_modules structure
node_modules/
require/
bin/
require-command.js
还有我的system.config.js
And my system.config.js
map: {
// a bunch of stuff listed in my previous post (https://stackoverflow.com/questions/41837321/how-do-i-properly-set-up-my-systemjs-config-for-use-with-ng2-codemirror/41841878#41841878)
'require' : 'npm:require',
},
packages: {
// some package definitions found in my previous post
'require' : {
format: 'global',
main: 'bin/require-command.js',
defaultExtension: 'js'
}
}
这是我最好的尝试,包含" require,但这对我没有用.有谁知道如何使ng2-codemirror模块可以使用需求?
This was my best attempt to "include" require, but it isn't working for me. Does anyone know how to make require available to this ng2-codemirror module?
我去抓取了CDN版本的require
I went and grabbed a CDN version of require
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js"></script>
并将其粘贴在index.html中...现在,我似乎得到了不同的堆栈跟踪.
And stuck it in my index.html... now I seem to be getting a different stack trace.
Error: (SystemJS) Module name "@angular/core" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
makeError@https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js:168:17
localRequire@https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js:1433:44
requirejs@https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js:1794:16
@http://localhost:8050/node_modules/ng2-codemirror/lib/codemirror.module.js:8:14
ZoneDelegate.prototype.invoke@http://localhost:8050/node_modules/zone.js/dist/zone.js:232:17
Zone.prototype.run@http://localhost:8050/node_modules/zone.js/dist/zone.js:114:24
scheduleResolveOrReject/<@http://localhost:8050/node_modules/zone.js/dist/zone.js:502:52
ZoneDelegate.prototype.invokeTask@http://localhost:8050/node_modules/zone.js/dist/zone.js:265:21
Zone.prototype.runTask@http://localhost:8050/node_modules/zone.js/dist/zone.js:154:28
drainMicroTaskQueue@http://localhost:8050/node_modules/zone.js/dist/zone.js:401:25
ZoneTask/this.invoke@http://localhost:8050/node_modules/zone.js/dist/zone.js:339:25
Evaluating http://localhost:8050/node_modules/ng2-codemirror/lib/codemirror.module.js
Error loading http://localhost:8050/app/main.js
似乎角铁/角铁尚不可用..?无论如何,这似乎是错误的方法.
It looks like the angular/core isn't available yet..? This seems like the wrong way to go about it anyways.
推荐答案
我已经解决了这个问题.
I have solved this.
我的代码镜像名称空间有点超出范围.
My code mirror namespace was a little out of scope.
我有这样的感觉
map : {
'ng2-codemirror' : 'npm:ng2-codemirror/lib'
},
packages : {
'ng2-codemirror' : {
main : 'index.js',
defaultExtension: 'js'
}
}
我需要像这样
map : {
'ng2-codemirror' : 'npm:ng2-codemirror'
},
packages : {
'ng2-codemirror' : {
main : 'lib/index.js',
defaultExtension: 'js'
}
}
我认为,通过在map部分中声明该文件夹为ng2-codemirror/lib,我就错失了一些包含的依赖项或某些内容.
I think by declaring the folder to be ng2-codemirror/lib inside the map section, I was missing out on some included dependencies or something.
这篇关于如何正确包含“要求"在我的angular 2项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!