发表文章

[Javascript] SyntaxError: 无效的正则表达式: 缺少/ "SyntaxError: Invalid regular expression: missing /"[adonis-framework]

InterwebCounty 6月前 37

嗨, 这是奇怪的, 我不知道这是否是一个多尼斯的问题-但突然不接触我的应用程序了几天后, 它给了我一个错误, 当我需要这样的脚本:

var chordgenerator = require("./chordgenerator");

这是在一个控制器, 有一个 "chordgenerator. js" 文件在 Http/控制器

错误是:

"SyntaxError: 无效的正则表达式: 缺少/

at exports.runInThisContext (vm.js:53:16)

at Module._compile (module.js:374:25)

at Object.Module._extensions..js (module.js:405:10)

at Module.load (module.js:344:32)

at Function.Module._load (module.js:301:12)

at Module.require (module.js:354:17)

at require (internal/module.js:12:17)

at ChordsController.index (/Users/J/Sites/hyperboria/app/Http/Controllers/ChordsController.js:14:30)

at next (native)
at /Users/J/Sites/hyperboria/node_modules/adonis-framework/src/Middleware/index.js:248:12`

我没有碰它或更新任何东西-我被难倒了。

原文:

Hi, this is strange and I'm not sure if it's an Adonis issue - but suddenly after not touching my app for a couple of days it's giving me an error when I require a script like so:

var chordgenerator = require("./chordgenerator");

This is in a controller, there is a "chordgenerator.js" file in Http/Controllers

the error is:

` SyntaxError: Invalid regular expression: missing /

at exports.runInThisContext (vm.js:53:16)

at Module._compile (module.js:374:25)

at Object.Module._extensions..js (module.js:405:10)

at Module.load (module.js:344:32)

at Function.Module._load (module.js:301:12)

at Module.require (module.js:354:17)

at require (internal/module.js:12:17)

at ChordsController.index (/Users/J/Sites/hyperboria/app/Http/Controllers/ChordsController.js:14:30)

at next (native)
at /Users/J/Sites/hyperboria/node_modules/adonis-framework/src/Middleware/index.js:248:12`

I haven't touched it or updated anything - I'm stumped.

相关推荐
最新评论 (8)
thetutlage 6月前
1

如果您删除 chordgenerator 它是否正常工作?如果是, 则可以在 chordgenerator 文件中共享代码吗?

原文:

If you remove the chordgenerator does it works fine? If yes, then can you share the code within the chordgenerator file?

InterwebCounty 6月前
2

如果我删除它的工作, (除了它打破了不同的方式, 因为我删除了它), 我得到同样的错误在另一个文件, 我需要用同样的方式, 所以我不认为在 ' chordgenerator ' 文件的错误。

这些文件看起来像这样:

"模块. 导出 = {
goforit: 函数 () {
等等长函数

}
}`

自从我张贴这个我更新的节点和美男子的最新稳定的版本, 我仍然得到的错误。 就像我说的, 我没碰那玩意儿, 两天前就开始工作了, 现在不是了。 我认为这不是一个美男子的错误, 它看起来像在需要模块的东西, 也许是自动更新本身, 我不知道。

原文:

If I remove it it works, (except it breaks in different ways because I removed it) and I get that same error on another file I require in the same way, so I don't think the bug in the 'chordgenerator' file.

The files kind of look like this:

` module.exports = {
goforit:function(){
//blah blah long function

}
}`

Since I posted this I updated Node and Adonis to the newest stable versions and I'm still getting the error. And like I said, I didn't touch the damn thing, it was working two days ago and now it isn't. I'm thinking it's not an Adonis error, it looks like something in the Require module, maybe something auto-updated itself, I have no clue.

InterwebCounty 6月前
3

此外, "var 异步 = 要求 (" 异步 "); 或类似的作品只是罚款。

原文:

Also "var async = require('async');" or similar works just fine.

thetutlage 6月前
4

如果在文件顶部添加 use strict 语句, 会发生什么情况?

原文:

What happens if you add use strict statement on the top of the file?

InterwebCounty 6月前
5

不, 没有零钱。

原文:

Nope, no change.

InterwebCounty 6月前
6

你认为它可能是美男子吗?

原文:

Do you think it could be Adonis?

thetutlage 6月前
7

是有点奇怪为什么需要这种方式的行为。当 v8 无法解析文件且错误无效时, 就会发生这种情况。

不, 我不认为阿多尼斯与它有什么, 因为它是一个正常的 require 调用。

我所能建议的是, 确保您没有使用带有箭头功能的 Es6 generators

这是错误的

*someFunction==> {

}

这是正确的

*someFunction=function () {

}
原文:

Yeah kind of weird on why require behaves this way. It happens when v8 is not able to parse the file and the errors are not helpful.

Nope I don't think Adonis has anything to do with it, since it is a normal require call.

All I can suggest is to make sure you are not making use of Es6 generators with arrow functions.

This is wrong

* someFunction = () => {

}

This is correct

* someFunction = function () {

}
InterwebCounty 6月前
8

我有其他错误, 我做了一个 "hello 世界" 文件, 并把它以同样的方式, 它没有打破。

谢谢你的帮助, 我可能会给你一些现金通过 Patreon。

原文:

I have something else wrong, I made a "hello world" file and included it in the same way and it didn't break.

Thanks for your help though, I'll probably throw you some cash through Patreon.

返回
发表文章
InterwebCounty
文章数
3
评论数
6
注册排名
48166