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
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 tonools.compile()
, thenfs.readFileSync()
is never called, so you can force webpack to resolverequire('fs')
to an empty object by adding this to your webpack config:See webpack's documentation of the
node
options: 1.x / 2.x