简体   繁体   English

如何在我的 angular 2 项目中正确包含“require”?

[英]How do I correctly include "require" in my angular 2 project?

I am still attempting to get the angular 2 code mirror module working within my angular 2 app.我仍在尝试让angular 2 代码镜像模块在我的 angular 2 应用程序中工作。

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...所以,我没有可用的需求...

This is my node_modules structure这是我的 node_modules 结构

node_modules/
    require/
        bin/
            require-command.js

And my system.config.js还有我的 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'
    }
}

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?有谁知道如何使这个 ng2-codemirror 模块可以使用 require ?

Edit :编辑 :

I went and grabbed a CDN version of require我去拿了一个 CDN 版本的 require

<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js"></script>

And stuck it in my index.html... now I seem to be getting a different stack trace.并将其粘贴在我的 index.html 中...现在我似乎得到了不同的堆栈跟踪。

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.我的代码镜像命名空间有点超出范围。

I had it like this我有这样的

map : {
    'ng2-codemirror' : 'npm:ng2-codemirror/lib'
},
packages : {
    'ng2-codemirror' : {
        main : 'index.js',
        defaultExtension: 'js'
    }
}

And I needed it to be like this我需要它像这样

map : {
    'ng2-codemirror' : 'npm:ng2-codemirror'
},
packages : {
    'ng2-codemirror' : {
        main : 'lib/index.js',
        defaultExtension: 'js'
    }
}

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.我认为通过在 map 部分将文件夹声明为 ng2-codemirror/lib ,我错过了一些包含的依赖项或其他东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM