Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strict mode syntax #417

Closed
fibo opened this issue Feb 12, 2016 · 4 comments

Comments

@fibo
Copy link

commented Feb 12, 2016

@feross few days ago commented #287 (comment)

if for example I have a script like

#!/usr/bin/env node

const msg = 'Hello world'
console.log(msg)

node will complain something like

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

but if I had "use strict" as you suggested, standard js will not accept it cause it is double quoted. I tryed with single quotes, but it does not work. Any hint?

@feross

This comment has been minimized.

Copy link
Member

commented Feb 12, 2016

What version of node are you using? I'm running v4.3.0 and your code example works fine without the need for 'use strict'.

@feross feross closed this Feb 12, 2016

@fibo

This comment has been minimized.

Copy link
Author

commented Feb 12, 2016

Yes, sorry the error reported when requiring a file, here it is the complete code

script.js

#!/usr/bin/env node
"use strict"

let config = require('./config')

// just a check
console.log(config)

config.js

const fs = require('fs')
const mdconf = require('mdconf')
const path = require('path')

const readme = fs.readFileSync(path.join(__dirname, '..', 'README.md'), 'utf8')

let config = mdconf(readme).database.configuration

module.exports = config
@feross

This comment has been minimized.

Copy link
Member

commented Feb 12, 2016

You're missing 'use strict' in config.js. standard will not complain about a single quoted 'use strict' and that will work just fine.

@feross feross added the question label Feb 12, 2016

@fibo

This comment has been minimized.

Copy link
Author

commented Feb 12, 2016

Yes it works, thanks. I am glad anout that cause I am using standard js in a lot of my packages, thanks for creating it.

Let me report a working example

script.js

#!/usr/bin/env node
'use strict'

let config = require('./config')

// just a check
console.log(config)

config.js

'use strict'

const config = {foo: 1}

module.exports = config

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.