How to import nools with es6 and webpack

127 views Asked by At

I want import nools in my project with webpack, and I try in 2 steps :

1) install nools with npm :

npm install nools --save

2) import nools in to the project :

import "../node_modules/nools";

webpack give me this error :

Can not resolve 'fs'

and solve this error with add this code to webpack.config.js

target:node

and webpack build without any error , but when start my project with npm start ,browser console give me this error :

require is not defined

my problem is how to import nools with webpack

1

There are 1 answers

0
Spencer On

It looks like nools needs the fs module to read a file from disk if a file path (rather than the source string itself) is passed to nools.compile().

Assuming your browser-based usage of nools in your webpack project never passes a *.nools string to nools.compile(), then fs.readFileSync() is never called, so you can force webpack to resolve require('fs') to an empty object by adding this to your webpack config:

node: {
  fs: 'empty'
}

See webpack's documentation of the node options: 1.x / 2.x