Yadda za a gyara da kumburi JS “SyntaxError: M alama shigo da” lokacin amfani da JavaScript kayayyaki

Domin ga kumburi don fitarwa kayayyaki kana da sanya kowane aiki, abu ko m, cewa bukatar da za a fitar dashi, kamar yadda kaddarorin da modules.exports ƙi.

 

Fitar da

In this example the module file is robot.js. Each function, abu ko m muna son yin samuwa ga wasu fayiloli mu sanya su kaddarorin da fitarwa abu.

robot.js (module fayil)

exports.sayHello =

(Sažon) => console.log('Hello peeps!')


exports.hello = "Hello!"


exports.greetings =

  { english : "Hello!",

    faransa : "Hello!",

    Spain: "Ola!"

  }

 

shigo da

Kumburi ba ya goyon bayan da shigo da sanarwa, saboda haka tsohuwar bukatar aiki bukatar a yi amfani da lokacin da sayo.

A nan mun shigo robot.js (bayanin kula: .JS iya optionally a bar fitar a cikin bukatar aiki) and assign it to an object that we can name anything. We name it robot. Our robot object now holds our exported modules from robot.js

Za mu iya amfani da shi kamar haka…

app.js (babban fayil)

const robot = bukatar('./robot')


robot.sayHello()

console.log(robot.hello)

console.log(robot.greetings.french)

Ka tuna ka yi amfani da abu sunan da ka zaba a farko line lokacin amfani da module m, aiki ko abu.

Note: Browsers do not support the require statement. Therefore you cannot use the require import module function with browsers without using a transpiler such as Babel or a bundler such as Browserify.

Uncaught ReferenceError - buƙaci ba a tsare a Opera Web browser v51

Require module import function in JavaScript is not supported in Web Browsers

Leave a Reply