adonisjs / core

AdonisJS is a TypeScript-first web framework for building web apps and API servers. It comes with support for testing, modern tooling, an ecosystem of official packages, and more.
https://adonisjs.com
MIT License
16.8k stars 637 forks source link

SyntaxError: Invalid regular expression: missing / #488

Closed InterwebCounty closed 7 years ago

InterwebCounty commented 7 years ago

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.

thetutlage commented 7 years ago

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

InterwebCounty commented 7 years ago

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 commented 7 years ago

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

thetutlage commented 7 years ago

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

InterwebCounty commented 7 years ago

Nope, no change.

InterwebCounty commented 7 years ago

Do you think it could be Adonis?

thetutlage commented 7 years ago

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 commented 7 years ago

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.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.