Meteor import from outside the `/imports` directory - meteor

I have files in a /models/ directory off the root of the Meteor application. That directory is in .meteorignore so it’s not automatically loaded.
I can’t do import SomeModule from '/models/some-module.js' from a file in the /imports/ directory. In some-module.js, the error says that the export or import (at the top of the some-module.js file) is an error.
export default function () {
^^^^^^
SyntaxError: Unexpected reserved word
at Object.exports.runInThisContext (vm.js:53:16)
at /Users/sunnyhirai/Projects/kb/.meteor/local/build/programs/server/boot.js:332:30
at Array.forEach (native)
at Function._.each._.forEach (/Users/sunnyhirai/.meteor/packages/meteor-tool/.1.5.4_2.1glyugb.deq2++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /Users/sunnyhirai/Projects/kb/.meteor/local/build/programs/server/boot.js:158:5
at /Users/sunnyhirai/Projects/kb/.meteor/local/build/programs/server/boot.js:388:5
at Function.run (/Users/sunnyhirai/Projects/kb/.meteor/local/build/programs/server/profile.js:510:12)
at /Users/sunnyhirai/Projects/kb/.meteor/local/build/programs/server/boot.js:387:11
In other words it is treating /models/ directory different than /imports/ directory. The same file in the /imports/ directory will import fine.
Please, if anybody knows how to fix this without moving all the files into /imports/ I would be grateful.

Have you tried:
import {SomeModule}from '/models/some-module.js'

Related

bjam fails the notfile example from the documentation?

I have seen boost-build / bjam: execute a script post install (make 'install' a dependency of executing a script) where there is a recommendation for using notfile. Then I found the https://www.boost.org/build/doc/html/bbv2/builtins/raw.html page with a basic example, where I've added the import notfile:
import notfile;
notfile echo_something : #echo ;
actions echo
{
echo "something"
}
And I've tried this snippet in a Jamroot file of a project. If I do not have the import notfile, then it fails with:
...
Jamroot:57: in modules.load
ERROR: rule "notfile" unknown in module "Jamfile</home/USER/src/myproject>".
/usr/share/boost-build/src/build/project.jam:372: in load-jamfile
/usr/share/boost-build/src/build/project.jam:64: in load
/usr/share/boost-build/src/build/project.jam:142: in project.find
/usr/share/boost-build/src/build-system.jam:618: in load
/usr/share/boost-build/src/kernel/modules.jam:295: in import
/usr/share/boost-build/src/kernel/bootstrap.jam:139: in boost-build
/usr/share/boost-build/boost-build.jam:8: in module scope
If I have the import notfile; then it fails with:
Jamroot:56: Unescaped special character in argument notfile;
/usr/share/boost-build/src/kernel/modules.jam:258: in modules.import from module modules
error: When loading multiple modules, no specific rules or renaming is allowed
/usr/share/boost-build/src/build/project.jam:1121: in import from module Jamfile</home/USER/src/myproject>
Jamroot:62: in modules.load from module Jamfile</home/USER/src/myproject>
/usr/share/boost-build/src/build/project.jam:372: in load-jamfile from module project
/usr/share/boost-build/src/build/project.jam:64: in load from module project
/usr/share/boost-build/src/build/project.jam:142: in project.find from module project
/usr/share/boost-build/src/build-system.jam:618: in load from module build-system
/usr/share/boost-build/src/kernel/modules.jam:295: in import from module modules
/usr/share/boost-build/src/kernel/bootstrap.jam:139: in boost-build from module
/usr/share/boost-build/boost-build.jam:8: in module scope from module
How can I get this to work?
Just noticed the "Jamroot:56: Unescaped special character in argument notfile" while writing the question which finally made sense (errors like "error: When loading multiple modules, no specific rules or renaming is allowed" are completely misleading and useless) - and I realized, I had written:
import notfile;
... that is, with semicolon directly after the word - it seems, here space is required; so with this change:
import notfile ;
... things start working again.

Module not found: Turborepo wildcard imports

When using Turborepo's wildcard imports (snippet from package.json)
dependencies: {
"branding": "*"
}
inside of a React app created with create-react-app, I get the error:
ERROR in ./src/App.js 5:0-37
Module not found: Error: Can't resolve 'branding' in 'C:\Users\****\Projects\Development\monorepo\apps\share\src'
I think I'm doing something very wrong, but I can't work it out through Turborepo's documentation.

How to fix: "deno error: Cannot resolve module 'x'"

I've got an error like so:
error: Cannot resolve module "<path>/src/routes" from "<path>/src/index.ts"
Imported from "file:///F:/Development/k8demo/api-deno/src/index.ts:2"
My problem was that Deno requires a .ts extension for imports unlike node.
Fix by adding .ts to the import.

MeteorJS not displaying anything on running application in localhost:3000

I am new to MeteorJS, and I am using Linux. As a basic newbie, I decided to stick to the tutorials on their official website. I went to follow the to-do list tutorial and selected the blaze option. At around step 6 or 7 the tutorial mentioned that you should start to see your application come together in your localhost:3000 when running it. After starting meteor and waiting for it to build the application I opened up localhost:3000. it looked like this:
AppImage. I thought there was an issue with my meteor installation so I ran
meteor npm install
to check if my installation was up to date and the output was:
up to date in 12.362s
I couldn't figure out what was wrong since the terminal wasn't sending any requests either so I opened the console in my browser and was greeted by the following errors:
Uncaught Error: Cannot find module './main.html'
at makeMissingError (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:232)
at Module.resolve (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:238)
at Module.moduleLink [as link] (modules.js?hash=20efd7567f62601be7ae21d11e21baf9bd63c715:307)
at module (main.js:1)
at fileEvaluate (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:346)
at Module.require (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:248)
at require (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:268)
at app.js?hash=b426fd76718daefbb34707a544746de2f90dc26c:258
Is there any way to fix this?
Thanks a lot.
edit
Some of you wanted to take a look at the main HTML and js files in the client directory, so I've included them here:
main HTML and JS:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
import '../imports/ui/body.js';
Template.hello.onCreated(function helloOnCreated() {
// counter starts at 0
this.counter = new ReactiveVar(0);
});
Template.hello.helpers({
counter() {
return Template.instance().counter.get();
},
});
Template.hello.events({
'click button'(event, instance) {
// increment the counter when button is clicked
instance.counter.set(instance.counter.get() + 1);
},
});
<head>
<title>simple-todos</title>
</head>
How to read the stack trace:
at module (main.js:1)
In main.js on line 1 you are trying to import your main.html file.
Cannot find module './main.html'
Your main.js file likely has a statement like import './main.html'; on the first line.
This means that you must not have a main.html file adjacent to your JS file and so it cannot include it in the build.
Verify spelling, case, and location of the file (what folder it belongs in). They need to be siblings in the same folder.

Meteor + React issue where once I add a router to my project, it rejects my import from .scss because it expects a node module

My app works perfectly fine without a router. I'm using the nathantreid:css-modules package, which allows modular css for your react components. Within my imports/ui/Navbar directory, I have Navbar.jsx, containing:
// Custom Dependencies
import s from './Navbar.scss';
import NavButton from './NavButton/NavButton';
When I have the app load the components in client/main.jsx with the following:
Meteor.startup(() => {
render(<App />, document.getElementById('render-target'));
});
It works, but it doesn't work when I add either react or flow router and create a route:
FlowRouter.route('/', {
action() {
mount(App);
}
});
It throws the following:
W20160520-10:09:25.659(-7)? (STDERR) Error: Cannot find module './Navbar.scss'
W20160520-10:09:25.659(-7)? (STDERR) at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:78:1)
W20160520-10:09:25.659(-7)? (STDERR) at meteorInstall.imports.ui.Navbar.Navbar.jsx (imports/ui/Navbar/Navbar.jsx:7:1)
W20160520-10:09:25.659(-7)? (STDERR) at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:141:1)
Would appreciate any technical insight as to how I might be able to fix this issue.
Also I would like to note that I've tried relative and absolute pathing, but the fundamental issue is that it only looks for NPM packages the moment I add a router (or at least that's my interpretation of what's happening).
I figured out a solution!
My underlying assumption might be wrong, but I think it has to do with load order. I moved my routes from the standard lib/ folder into my imports/ folder where I also have my other react modules. I then just imported/required the routes in my client/main.jsx and it worked!

Resources