How do I import a library from the lib folder in my web app? - dart

My folder structure looks like this:
lib\
my_library.dart
web\
index.html
main.dart
pubspec.yaml
In main.dart, I'm currently importing my_library.dart (which has library my_library at the top) by doing:
import '../lib/my_library.dart';
This works fine. However, it feels a bit fragile to have this relative path. I read in the Pub Package Layout Conventions that I can probably use import 'package:blah'; it says:
When you use libraries from within your own package, even code in src, you can (and should) still use "package:" to import them
So, I tried changing my code to this:
import 'package:my_library.dart';
However, in Chrome Dev Editor I get:
Target or URI does not exist: 'package:grid_data.dart'
and in Dartium I get:
GET http:// 127.0.0.1:51792/MyProject/web/packages/my_library.dart 404 (Not Found)
What's the correct way to import something from my lib folder from other dart files in my project?

You are missing the package name
import 'package:my_project/my_library.dart';
The package: part in your import statement references the packages folder in your my_project package (the folder that contains the pubspec.yaml. The remainder of the import statement is the path to the file you want to import.
You can browse through the folders and files in this packages folder in DartEditor or a file manager to see exactly how the files are organized.
This folder also contains a symlink named my_project which points to your my_project/lib folder.

Related

vite throws file not found error when bootstrap5 added to sveltekit app.html

I added bootstrap5 via style and script tags in app.html
bs5 works fine but vite throws error that files are not found.
any advice?
Error message
Error: Not found: /vendors/bootstrap-5.0.2/bootstrap.min.css.map
Error: Not found: /vendors/bootstrap-5.0.2/bootstrap.bundle.min.js.map
files located:
/static/vendors/bootstrap-5.0.2/bootstrap.min.scss
/static/vendors/bootstrap-5.0.2/bootstrap.bundle.min.js
I would not recommend adding anything to the app.html, instead import from a root +layout.svelte, installing bootstrap from NPM.
The errors refer to .map files that specify what parts of a minified JS file refer to which lines in a source file. You probably did not copy the files over, so they cannot be found. The files are reference from the .min.js files.
But as noted, one should not import scripts like that.
When installing from NPM you need the packages:
bootstrap
#popperjs/core
It is possible to import just the code for specific components and compile the CSS from source (see docs). To import all code and styles you just need:
<script>
import 'bootstrap';
import 'bootstrap/dist/css/bootstrap.css';
</script>
It is preferred to only import what is actually needed to reduce the resulting bundle size.

macOS - How can I install a new MacTex (LaTeX) package (a folder containing .sty or .bib files) and use it?

I have been struggling to install a new package and use it for TexShop.
What I have tried is searching for the folder path: /texmf/tex/latex
However, even when enabling to see hidden folders, such a folder does not exist on my system. I therefore went ahead and created the three folder manually. I then placed my folders containing the .sty or .bib files inside. This does not seem to be working because I still receive the error that LaTeX could not find the .sty file.
Another folder that I can find within my Library is not the texmf folder but a TeX folder (see screenshot below)
Do I maybe have to place the packages inside one of these folders instead?

Package.swift manifest not found ("has no Package.swift manifest for ...")

Using the default flow to create new Swift Package, I created one and put it in a bitbucket repo. The files inside have the following structure:
The problem is that, when i try to add it to a project, i get an error that Package.swift is not found.
It seems, that the Package.swift file is not found, if it is not on the root level level of the repo. But if i move the Package.swift file on the same level as "TestSwiftPackage" root folder, the package dependencies all get broken.
I tried to add specific paths for target and testTarget, but it still wont work.
How should the Package.swift look like to make this work?
I found the issue with the Package setup.
Just have to find the correct paths to both targets.
Here is the working setup.

Dart pub get command is not working properly when i try to pull my dependencies

I have my project in github. I already created it like a library (Dart). Now I am trying to use my library in one of my project.
After i add all the necessary comments to get it from my git source, pub get is giving the following error,
Warning: Package <library_name> does not have a "lib" directory so you will not be able to import any libraries from it.
Got dependencies!
Any clue???
Thanks,
Tham
When importing libraries, the files you import come from the lib folder.
Eg:
import 'package:danny/danny.dart';
will import the file lib/danny.dart from the danny package.
If the package doesn't have a lib folder; this means you can't possibly import it. If you're importing directly from a Git repo; you need to ensure the lib folder is a top-level folder.

Failed to load package in Dart

When I try to import a package with the syntax import 'package:markdown/markdown.dart';, I get no error in Dart Editor but when I run the dart application, the debugger shows me the message:
An error occurred loading file: package:markdown/markdown.dart
Failed to load resource
chrome-extension://gfjabgeipkcfopofkhjimepepnomcidk/dart/packages/markdown/markdown.dart
But when I write the whole path (import "../../packages/markdown/markdown.dart";) everything works fine. I cannot understand why the syntax package: doesn't work in my code though it works in Dart Editor's own examples.
You can see the Chrome app architecture below (I'm loading a package from translator.dart):
You should have the package added as a dependency in pubspec.yaml (which I assume you do).
Also try running following:
delete packages folder
delete pubspec.lock
run pub get to fetch the
dependencies again.
I think in your md_to_html folder you need a link to the 'packages' directory for the shortform to work. I seem to remember this happening when the workspace is built but I'm not sure now which command triggers it, have a look at the current pub docs.

Resources