Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM - Browserify "'import' and 'export' may appear only with 'sourceType: module'"

I am trying to convert a file tensorflow.js file (written in Node.js) with Browserify into plain Javascript. In the file there are two lines

import * as tf from '@tensorflow/tfjs';
import {MnistData} from './data';

When I am exporting this I am getting the error "ParseError: 'import' and 'export' may appear only with 'sourceType: module'". How can I solve this error?

Many thanks in advance, Andi

like image 617
Andi Maier Avatar asked Jun 25 '18 12:06

Andi Maier


1 Answers

You can use esmify to add ES Modules support to browserify:

browserify index.js -p esmify > bundle.js

Refer to the project's readme for more usage info.

like image 92
fregante Avatar answered Nov 15 '22 20:11

fregante