GochoMugo / tgfancy

A Fancy, Higher-Level Wrapper for Telegram Bot API
MIT License
184 stars 16 forks source link

Loading module 'telegram'... SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode #1

Closed phillipadsmith closed 7 years ago

phillipadsmith commented 7 years ago

@GochoMugo Being blissfully ES6 ignorant, I'm stuck trying to update the Telegram module for Concierge (previously known as Kassy) with the following error:

Loading module 'telegram'...
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
  at exports.runInThisContext (vm.js:53:16)
  at Module._compile (module.js:387:25)
  at Module._extensions..js (module.js:422:10)
  at Object.require.extensions.(anonymous function) [as .js] (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/babel-register/lib/node.js:152:7)
  at Module.load (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
  at Function.Module._load (module.js:314:12)
  at Module.require (module.js:367:17)
  at require (internal/module.js:16:19)
  at Object.<anonymous> (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/tgfancy/lib/index.js:10:16)
  at Module._compile (module.js:413:34)
  at Module._extensions..js (module.js:422:10)
  at Object.require.extensions.(anonymous function) [as .js] (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/babel-register/lib/node.js:152:7)
  at Module.load (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
  at Function.Module._load (module.js:314:12)
  at Module.require (module.js:367:17)
  at require (internal/module.js:16:19)
  at fs.readdirSync.forEach.installAndRequire (/Users/phillipadsmith/Development/concierge-plus-br/core/unsafe/require.js:96:15)
  at func (/Users/phillipadsmith/Development/concierge-plus-br/core/unsafe/require.js:124:21)
  at Object.<anonymous> (/Users/phillipadsmith/Development/concierge-plus-br/modules/kpm_telegram/telegram.js:3:15)
  at Module._compile (module.js:413:34)
  at loader (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/babel-register/lib/node.js:144:5)
  at Object.require.extensions.(anonymous function) [as .js] (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/babel-register/lib/node.js:154:7)
  at Module.load (/Users/phillipadsmith/Development/concierge-plus-br/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
  at Function.Module._load (module.js:314:12)
  at Module.require (module.js:367:17)
  at require (internal/module.js:16:19)
  at fs.readdirSync.forEach.installAndRequire (/Users/phillipadsmith/Development/concierge-plus-br/core/unsafe/require.js:96:15)
  at func (/Users/phillipadsmith/Development/concierge-plus-br/core/unsafe/require.js:124:21)
  at /Users/phillipadsmith/Development/concierge-plus-br/core/modules/kassy/kassyModule.js:66:17
  at Object.exports.loadModule (/Users/phillipadsmith/Development/concierge-plus-br/core/modules/kassy/kassyModule.js:94:35)
  at ModuleLoader._loadModuleInternal (/Users/phillipadsmith/Development/concierge-plus-br/core/modules/modules.js:31:59)
  at ModuleLoader.loadModule (/Users/phillipadsmith/Development/concierge-plus-br/core/modules/modules.js:118:27)
  at ModuleLoader.loadAllModules (/Users/phillipadsmith/Development/concierge-plus-br/core/modules/modules.js:156:30)
  at Platform.start (/Users/phillipadsmith/Development/concierge-plus-br/core/platform.js:181:32)
  at Object.exports.run (/Users/phillipadsmith/Development/concierge-plus-br/core/startup/startup.js:48:18)
  at Object.<anonymous> (/Users/phillipadsmith/Development/concierge-plus-br/main.js:45:9)
  at Module._compile (module.js:413:34)
  at Object.Module._extensions..js (module.js:422:10)
  at Module.load (module.js:357:32)
  at Function.Module._load (module.js:314:12)
  at Function.Module.runMain (module.js:447:10)
  at startup (node.js:142:18)
  at node.js:939:3

This is a vanilla/default install of Concierge with the existing Telgram integration loaded, and where I've substituted tgfancy for node-telegram-bot-api When I try to start the integration, it fails per the above message.

Any help around my ignorance here greatly appreciated. :-)

kamikazechaser commented 7 years ago

@phillipadsmith Could you specify the Node.js version you are using?

phillipadsmith commented 7 years ago

@kamikazechaser

➜ concierge-plus-br git:(master) ✗ node -v v5.9.0

kamikazechaser commented 7 years ago

@phillipadsmith I'm trying to test Concierege but I end up getting a "!CORE!" threw up. <unknown> is now covered in sick.

phillipadsmith commented 7 years ago

I'm trying to test Concierege but I end up getting a "!CORE!" threw up. is now covered in sick.

Hmmm... that's not good.

What steps did you take to test?

phillipadsmith commented 7 years ago

cc @mrkno

kamikazechaser commented 7 years ago

@phillipadsmith @mrkno

Installation Bit

git clone https://github.com/concierge/Concierge.git
cd Concierge
npm install
npm start 

Running The Bot

/kpm install telegram
/kpm config telegram username "aaaaabbb:CCC888999" (My Actual Bot Token Here)
/kpm config telegram commandPrefix "/"
/kpm start telegram 

It returns

"!CORE!" threw up. <unknown> is now covered in sick.

phillipadsmith commented 7 years ago

Odd. That's not what happened for me. What version of Node?

kamikazechaser commented 7 years ago

Tested on both v6.5.x and v7.2.x

phillipadsmith commented 7 years ago

Okay, let me give that a try...

phillipadsmith commented 7 years ago

@kamikazechaser It's a documentation error (I'll fix up now). Try:

/kpm config telegram token AbcXyz

Telegram requires a token property, not a username property.

phillipadsmith commented 7 years ago

However, @mrkno, should the error message from Concierge be more helpful than that?

drkno commented 7 years ago

If you don't start with the --debug argument it suppresses stack traces (and cause the core loader failed to load your module, rather than your module actually loading then failing it assumes that the core platform was at fault, hence !CORE!) as many stack-traces from Concierge aren't actually problems with Concierge itself. Not entirely certain why you are getting your exception however, cause if babel is loading correctly it should be editing your code to have a "use strict"; at the top. Concierge babel does not touch npm modules, and your version of node is old enough that it won't allow ES6 const and let without "use strict"; defined in each file (babel does this for all other files in Concierge). If both https://github.com/GochoMugo/tgfancy/blob/master/lib/client.js and https://github.com/GochoMugo/tgfancy/blob/master/lib/index.js have this defined at the top of them, it will solve this problem in older versions of node.

phillipadsmith commented 7 years ago

If you don't start with the --debug argument it suppresses stack traces (and cause the core loader failed to load your module, rather than your module actually loading then failing it assumes that the core platform was at fault, hence !CORE!)

Makes sense.

Concierge babel does not touch npm modules, and your version of node is old enough that the ES6 const and let without "use strict"; defined in each file (babel does this for all other files in Concierge). If both https://github.com/GochoMugo/tgfancy/blob/master/lib/client.js and https://github.com/GochoMugo/tgfancy/blob/master/lib/index.js have this defined at the top of them, it will solve this problem in older versions of node.

Okay, confirmed with v7.2.1 that there's no error message.

However, I'm having other issues, which I'll ask about in the Concierge repo.

Thanks @mrkno !

GochoMugo commented 7 years ago

For completeness, I suggest you use the latest Node.js version which supports ES6 out of the box. I am not seeking to support older Node.js versions, in a bid to force people to use the newer versions. Sorry about that!

phillipadsmith commented 7 years ago

@GochoMugo No need to apologize; I completely understand. :-)

kamikazechaser commented 7 years ago

@phillipadsmith I suggest you manually add the 'use strict' in the tgfancy files in node_modules/ folder. You should still be able to use tgfancy with the older versions, I believe so! 😉