Cannot require a txt file
kanishk-anand-oyo opened this issue · 6 comments
I am trying to import a .txt file using raw-loader.
If I use var text=require(raw!./sample.txt)
I get raw!./sample.txt not fount and if I use var txt=require(./sample.txt)
I get this error:
(function (exports, require, module, __filename, __dirname) { html ....} SyntaxError: Unexpected token { at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous>
Can anyone explain?
@kanishk-anand-oyo use full name raw-loader
-> var text=require("raw-loader!./sample.txt");
Still the same error of cannot find the module
@kanishk-anand-oyo npm i -D raw-loader
@evilebottnawi
Still the same error, how ever running npm i -D raw-loader
gave the following output:
@0.0.1 /Users/username/repo ├── raw-loader@0.5.1 ├── UNMET PEER DEPENDENCY react@16.2.0 extraneous └── UNMET PEER DEPENDENCY react-dom@^0.14.0 || 15.x.x npm WARN react-addons-css-transition-group@15.6.2 requires a peer of react@^15.4.2 but none was installed. npm WARN react-daterange-picker@1.2.0 requires a peer of react@^0.14.0 || 15.x.x but none was installed. npm WARN react-daterange-picker@1.2.0 requires a peer of react-dom@^0.14.0 || 15.x.x but none was installed. npm WARN react-input-range@1.3.0 requires a peer of react-dom@^15.0.0 || ^16.0.0 but none was installed. npm WARN react-json-tree@0.11.0 requires a peer of react-dom@^15.0.0 || ^16.0.0 but none was installed. npm WARN react-lazy-load@3.0.13 requires a peer of react-dom@^0.14.0 || ^15.0.0-0 || ^16.0.0 but none was installed. npm WARN react-scroll@1.7.6 requires a peer of react-dom@^15.5.4 || ^16.0.0 but none was installed. npm WARN react-slick@0.14.11 requires a peer of react@^0.14.0 || ^15.0.1 but none was installed. npm WARN react-slick@0.14.11 requires a peer of react-dom@^0.14.0 || ^15.0.1 but none was installed. npm WARN react-transition-group@1.2.1 requires a peer of react-dom@^15.0.0 || ^16.0.0 but none was installed. npm WARN slick-carousel@1.8.1 requires a peer of jquery@>=1.8.0 but none was installed. npm WARN @0.0.1 No repository field.
Also, I didn't understand Don't forget to polyfill 'require' if you want to use it in node.
Sorry to ask silly questions, I am beginner :|
@kanishk-anand-oyo many of deps require difference react versions you should fix this (install right version). Also add into devDependencies
raw-loader
and reinstall all deps (rm -rf pachage-lock.json node_modules && npm i
)