简体   繁体   中英

Uncaught SyntaxError:Cannot use import statement outside a module

I'm trying to import a module that is called fs and I used require to import it. I then realized that to be able to use require I need to import it using this:

import {createRequire} from 'module';
const require = createRequire(import.meta.url);

but it gives me this error: Uncaught SyntaxError: Cannot use import statement outside a module

You need to assign the module property in script tag.

<script type="module">
     import { createRequire } from './module.js';
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM