In the process of learning ES6, an error is reported when and running JavaScript files, which is reproduced in detail
1. Create a new file, add test es, and use idea to open the folder
2. Add package.json file: NPM init – y
3. Create a new test.js file in the folder test-es, the contents of which are as follows
let a = 1111
let b = 2222
var c = function(){
console.log(3333)
}
function ddd(){
console.log(4444)
}
function eeeeee5(){
console.log(555)
}
export {
a,
b,
c,
ddd,
eeeeee5 as eee, //The way to rename: name eeeeeeee as eee, you can output the same variable or method with different names
eeeeee5 as e5 // rename the way: name eeeeee as eee, you can output the same variable or method with a different name
}
4. Right click and click Run ‘test.JS’, the error is reported as follows:
Solution:
According to the error message, in package JSON add “type”: “module”, and then run test.JS file, no error will be reported
Read More:
- The vue3 project Error: Cannot find module’vue-loader-v16/package.json’
- [Solved] Error: Cannot find module ‘vue-template-compiler/package.json‘ Require stack:
- [Solved] ERROR Error: Cannot find module ‘vue-loader-v16/package.json‘
- [Solved] Vite Error: Failed to load module script: Expected a JavaScript module script but the server…
- Module not found: Error: Can‘t resolve ‘core-js/modules/es.promise.js‘ in
- Module build failed: Error: Couldn’t find preset “es2015” relative to directory
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] Uncaught SyntaxError: Cannot use import statement outside a module
- [Solved] electron Package and Startup Error: Error: ENOENT: no such file or directory, open ‘xxx/manifest.json‘‘
- [Solved] TypeError: Converting circular structure to JSON – JSON.stringify
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] VS Code Error: Vetur can‘t find ‘tsconfig.json‘ or ‘jsconfig.json‘
- @requestbody: How to Use or Not Use
- [Solved] Uncaught SyntaxError: The requested module does not provide an export named
- How to Solve JS error: Unexpected end of JSON input,Unexpected token u in JSON at position 0
- js: SyntaxError: Cannot use import statement outside a module
- [Solved] Vue package error: Syntax Error: Error: Cannot find module ‘mozjpeg’
- [Solved] webpack Package Error: ERROR in multi ./src/main.js ./dist/bundle.js Module not found: Error: Can‘t resolv
- package.json Scripts configuration environment variable distinguishes development environment from production environment